Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-20 11:02:34
Original
1579 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template