Home >Backend Development >PHP Tutorial >How to randomly select one or more cells from an array_PHP Tutorial
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));
?>