What does array_rand() function in php.?
The array_rand() function returns a random key from an array, or it returns an array of random keys if you specify that the function should return more than one key.
Syntax of array_rand() function:
array_rand(array,number)
According to above syntax, there are two main Parameter of array_rand()
1- Array(this is used for specifing an array)
2- Number(Designates how many desultory keys to return)
You can see below example of array_rand() function in php.
<?php
//here ColorName is a variable
$ColorName=array("red","purple","blue","yellow","pink");
//here call array_rand() function
$result_;keys=array_rand($ColorName,4);
echo $ColorName[$result_keys[0]]."<br>";
echo $ColorName[$result_keys[1]]."<br>";
echo $ColorName[$result_keys[2]]."<br>";
echo $ColorName[$result_keys[3]];
?>
Output of above code will be as following:-
red
purple
blue
yellow
0 Comment(s)