Array_rand
(PHP4 >= 4.0.0)
Array_rand---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; Randomly select one or more values of an array
Syntax: mixed array_rand (array input [, int num_req])
Description:
Array_rand () is useful when you want to randomly select one or more of the values of an array, the argument num_reg is not necessary, it indicates that you want to select a few values out, if not specified, then its default value is 1.
If you select only one value, Array_rand () returns the index of the random value. Otherwise, it returns the index of the random value in the array and returns the array. This way you can not only pick random index values but also output the values of the array.
Don't forget to call Srand () to set the number of random seeds.
Example:
<?php
Srand (Double) microtime () * 10000000);
$input = Array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand _keys = Array_rand ($input, 2);
Print $input [$rand _keys[0]]. " \ n ";
Print $input [$rand _keys[1]]. " \ n ";
?>