|
|
Php Array Random Function
|
Tutorials » Php »
|
Topic |
What is array_rand Function?
|
|
Explanation |
|
The "array_rand" function returns a random element key from an array, or it
returns an array of random keys if required. This has to be specified.
Syntax:
array_rand(array,number)
In the above syntax "array" specifies the array from which the "number" of keys to be displayed, by default is its 1.
Example:
<?php
$b=array("c"=>"Cherry","b"=>"Strawberry");
print_r(array_rand($b,1));
?>
Result:
b
In the above example a random key is displayed as the "number" of keys is specified as 1.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|