Home>Article>Backend Development> PHP uses array_rand() function to randomly select one or more elements from an array_PHP Tutorial

PHP uses array_rand() function to randomly select one or more elements from an array_PHP Tutorial

John Lennon
John Lennon Original
2016-07-13 10:31:34 942browse

Use the array_rand() function to randomly select one or more elements from an array and return it.

Copy codeThe 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 codeThe code is as follows:

$a= array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
print_r(array_rand($a,1));
?>

Result:

b

www.bkjia.com true http: //www.bkjia.com/PHPjc/762210.html TechArticle Use 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...
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