Php array_rand random array value
Array_rand
(PHP 4 and PHP 5)
Array_rand-select an array of one or more random entries
Description
Hybrid array_rand (array $ input [Abstract $ num_req = 1])
Array_rand () is quite useful when you want to select an array of one or more random entries.
Parameters
Input
Input array.
Num_req
Specify the number of entries to select-if not specified, the default value is 1.
Return Value
If you select only one entry, key random entries returned by array_rand. Otherwise, it returns a random entry of the key of an array. You can select any key and value array.
Instance
Example of #1 array_rand ()
<? Php
Srand (float) microtime () * 10000000 );
$ Input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank ");
$ Rand_keys = array_rand ($ input, 2 );
Echo $ input [$ rand_keys [0]. "n ";
Echo $ input [$ rand_keys [1]. "n ";
?>