Use the array_rand() function to randomly select one or more elements from an array and return it.
Copy code The code is as follows:
array_rand(array,number)
Parameter description
array required. Specifies the input array parameters.
number optional. The default is 1. Specifies how many random elements to return.
Example:
Copy code The code is as follows:
$a= array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
print_r(array_rand($a,1));
?>
Result:
b
http://www.bkjia.com/PHPjc/762210.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/762210.htmlTechArticleUse the array_rand() function to randomly select one or more elements from the array and return it. Copy the code The code is as follows: array_rand(array,number) Parameter Description array Required. Specify the input number...