PHP - Function array_rand()
Syntax
array_rand ( $input [, $num_req] );
Definition and Usage
This function pick one or more random entries out of an array.
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
array(Required) It specifies an array. |
| 2 | num_req(Optional) It specifies how many entries you want to pick - if not specified, it defaults to 1. |
Return Values
It returns an array of keys for the random entries.
Example
Try out following example −
<?php
$input = array("a"=>"banana","b"=>"apple","c"=>"orange");
print_r(array_rand($input));
?>
This will produce the following result, This result will vary every time you will execute script −
b
php_function_reference.htm
Advertisements