array_rand() function

array_rand() function

Array_rand function is used to pick one or more elements from an array. We can use this function in sites to display random images.

Example :

<?php

srand ((float) microtime() * 10000000);

$input_array = array (”img1.jpg”, “img2.jpg”, “img3.jpg”, “img4.jpg”, “img5.jpg”);

$rand_keys = array_rand ($input_array, 2);

print $input_array[$rand_keys[0]].”\n”;

print $input_array[$rand_keys[1]].”\n”;

?>

In above example, we are picking 2 random images from input array.

Leave a Reply


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.