How to use array rand in PHP
In this article, I will explain how the array_rand() function can be used in PHP.
array_rand() function in PHP
-
The array_rand() function is used to returns a random entries from an array, or it returns an array of random keys if you specify that the function should return more than one key.
-
The array_rand() function fetch one or more random entries out of an array.
-
In array_rand() function, If the value of keys is 1, It return a random key.
Syntax
Parameter
Example
The following example show to how the array_rand() function can be used in PHP.
<html>
<body>
<h3 style="color: greenyellow;">array_rand() function example in PHP</h3>
<?php
$a=array("a"=>"Student","b"=>"teacher","c"=>"Engg.");
print_r(array_rand($a,2))."<br/>";
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here