Php uses the array_rand () function to randomly select one or more elements from the array. Use the array_rand () function to randomly select one or more elements from the array and return them. The copy code is as follows: the array_rand (array, number) parameter description is required for array. Specify the number of inputs. use the array_rand () function to randomly select one or more elements from the array and return them.
The code is as follows:
Array_rand (array, number)
Parameter description
Array is required. Specify the input array parameters.
Number is optional. The default value is 1. Specifies how many random elements are returned.
Example:
The code is as follows:
$ A = array ("a" => "Dog", "B" => "Cat", "c" => "Horse ");
Print_r (array_rand ($ a, 1 ));
?>
Result:
B
The random () function randomly selects one or more elements from the array and returns the result. The code is as follows: the array_rand (array, number) parameter must describe the array. Specify the number of inputs...