The Array_rand () function says so in the document:
mixed array_rand ( array $input [, int $num_req = 1 ] )
Parameters
Input
The input array.
Num_req
Indicates how many units you want to take out of the unit. If the specified number exceeds the number in the array, a e_warning level error is generated.
return value
If you only take one, Array_rand () returns the key name of a random cell, or returns an array containing the random key name. This allows you to randomly remove the key names and values from the array. Extracts one or more random cells from an array and returns one or more keys for a random entry.
So, to get the key name of the group will be repeated, the internet for a long time seems to have no explanation for this
Reply content:
The Array_rand () function says so in the document:
mixed array_rand ( array $input [, int $num_req = 1 ] )
Parameters
Input
The input array.
Num_req
Indicates how many units you want to take out of the unit. If the specified number exceeds the number in the array, a e_warning level error is generated.
return value
If you only take one, Array_rand () returns the key name of a random cell, or returns an array containing the random key name. This allows you to randomly remove the key names and values from the array. Extracts one or more random cells from an array and returns one or more keys for a random entry.
So, to get the key name of the group will be repeated, the internet for a long time seems to have no explanation for this
There is absolutely no repetition, I paste the main part of the source code, the algorithm is to loop through the array of elements, and then by the algorithm comparison, matching the key value into the return value, until the number of matching key is obtained or the array element cycle.
.
php
//键名应该不会有重复$arr = [1,2,3];$res = array_rand($arr,3);//总是[0,1,2]echo $arr[$res[0]];//1echo $arr[$res[0]];//2echo $arr[$res[0]];//3
Random elements suggest replacing with shufflearray_rand
http://www.php.net/manual/en/function.array-rand.php
Key names are definitely not duplicated.
The array's key name will never be repeated