Home  >  Article  >  Backend Development  >  How to randomly select one or more cells from an array_PHP Tutorial

How to randomly select one or more cells from an array_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:02:341541browse

To randomly extract one or more units from an array, we will use array_rand (), which is very useful when you want to extract one or more random units from an array. It accepts input as an input array and an optional parameter num_req, which specifies how many cells you want to remove - if not specified, it defaults to 1. If you only take out one, array_rand() returns the key name of a random cell, otherwise it returns an array containing the random key name

$a=array("a"=>"dog","b"=>"cat","c"=>"horse");
print_r(array_rand($a,1));
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445354.htmlTechArticleTo randomly select one or more units from an array, we will use array_rand () to select Useful when removing one or more random units. It accepts input as 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