$arry = array('A','B','C','D');$result = array_rand($arry,2);foreach ($result as $val) {echo $arry["$val"].""; }
Please ask, this will produce 2 group ABCD combinations such as BC DC AB, etc.
But what I'm trying to show is, just show one. Random from a number of a or B or C or D
Please ask how to do this?
I changed 2 to 1 and I lost it.
Reply content:
$arry = array('A','B','C','D');$result = array_rand($arry,2);foreach ($result as $val) {echo $arry["$val"].""; }
Please ask, this will produce 2 group ABCD combinations such as BC DC AB, etc.
But what I'm trying to show is, just show one. Random from a number of a or B or C or D
Please ask how to do this?
I changed 2 to 1 and I lost it.
mixed array_rand ( array $array [, int $num = 1 ] )# Picks one or more random entries out of an array, and returns the key (or keys) of the random entries. It uses a pseudo random number generator that is not suitable for cryptographic purposes.
The keys in the specified array are returned randomly, and $num
multiple keys are returned as a key or in 数组
the form of requirements.
If you have an array
现在想每次随机输出数组中的一个元素,则可以采用以下方式获取:
以此同理可以实现其他的随机元素键并获取数组的随机元素。
$array = Array (' A ', ' B ', ' C ', ' D '); $newArray = $array; Shuffle ($newArray); echo $newArray [0];
Picks one or more random entries out of an arr Ay, and returns the key
(or keys) of the random entries. It uses a pseudo random number
Generator that's not suitable for cryptographic purposes.
If the second argument is 1 or not, the return is not an array, but just a number
$ result = Array_rand ($arry, 2); is an array of * * * such as [Array_rand] $result = ($arry, 1); Just A * * number * * such as 1, not [1]