mercredi 4 octobre 2023

Retrieving the same value from multiple arrays

so I have two arrays each has 3 values. I need 2 random values ​​from each array. For example: From arr1 "red", "blue" and from arr2 "red", "blue". I need to randomly get the same keys from two arrays. and change the keys every time the page is updated. If you get keys 1 and 2 from arr1, then from arr2 you should also get keys 1 and 2, or from arr1 3 and 2, and from arr2 also 3 and 2. everything is random.

Code:
$arr1 = ['green', 'red', 'blue'];
$arr1 = ['green', 'red', 'blue'];
for ($i = 0; $i < 2; $i++){
echo $arr1[$i];
echo $arr2[$i];
}

I don't know how to implement this. I used the shuffle and rand functions but they don't work. shuffle gives incorrect results.




Aucun commentaire:

Enregistrer un commentaire