我确实有办法在数组中获取随机元素:
$array1 = array("Bird", "Animal", "Tower", "Car", "Tree");
$rand_keys = array_rand($input, 4);
echo $array1[$rand_keys[0]] . "\n";
echo $array1[$rand_keys[1]] . "\n";
echo $array1[$rand_keys[2]] . "\n";
echo $array1[$rand_keys[3]] . "\n";
但是,如果我有 3 个数组,我也可以随机化它们的元素:
$array1 = array("Bird", "Animal", "Tower", "Car", "Tree");
$array2 = array("Falcon", "Cat", "Man", "Poll", "Sea");
$array3 = array("Lion", "Apple", "Rock", "Ball", "Tea");
我怎样才能获得数组本身的垂直随机化?
我需要结果像这些模式:
Car Tree Bird Animal Tower // array1
Man Poll Falcon Cat Sea // array2
Rock Ball Tea Lion Apple // array3
如果我刷新页面,另一个:
Lion Apple Rock Ball Tea // array3
Animal Tower Car Tree Bird // array1
Man Cat Sea Poll Falcon // array2