I\'m trying to generate an array of random numbers from 0-n then shuffle (but ensure that the keys and values DO NOT match).
For example:
0 => 3
1
This will generate an array with 10 random numbers from 0 to 100:
array_map(function () {
return rand(0, 100);
}, array_fill(0, 10, null)
);
Result:
array(10) {
[0]=>
int(15)
[1]=>
int(97)
[2]=>
int(20)
[3]=>
int(64)
[4]=>
int(57)
[5]=>
int(38)
[6]=>
int(16)
[7]=>
int(53)
[8]=>
int(56)
[9]=>
int(22)
}
Explanation:
array_fill(0, 10, null) will generate an array with 10 empty itemsarray_map Applies the callback (first argument) to each item of the array it receives (second argument). In this example, we just return a random number for each array item.Playground: https://3v4l.org/FffN6