array_rand

array_rand

mixed array_rand ( array input [, int num_req] )

Is used to pick one or more random entries from an array.It takes an input array
and argument num_req is number of random entries we want to pick
which is optional one the default is 1.

If you pick one entry then the key of the entry is picked if the option is more than one then array of key are returned.

<?php

$array = array(’hai’,'this’,'is’,'an’,'example’);

$index = array_rand($array);

echo $array[$index];
//// Will output ‘hai’ or ‘this’ or ‘is’ or ‘an’ or ‘example’

?>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.