Home>Article>Backend Development> php array_rand() function randomly selects one or more elements from an array

php array_rand() function randomly selects one or more elements from an array

WBOY
WBOY Original
2016-07-25 09:13:05 1901browse
PHP uses the array_rand() function to randomly select one or more elements from an array. Use the array_rand() function to randomly select one or more elements from an array and return it. array_rand(array,number) Parameter Description array Required. Specifies the input array parameters. www.jbxue.comnumber Optional. The default is 1. Specifies how many random elements to return. Example: $a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
print_r(array_rand($a,1));
? > Result: b


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn