|
Posted by NC on 12/16/05 09:08
guttyguppy@gmail.com wrote:
>
> This code captures every file in the images directory into
> the fadeimages array. How can I tell php to randomly
> capture only 5 or so of the images and store only those
> in the array?
Instead of outputting every file name, store file names in an array
(lets say, $files) and then randomly draw five elements from that
array:
$n = count($files) - 1;
for ($i=1; $i <= 5; $i++) {
echo 'fadeimages[', $i, ']=["images/', $files[rand(0, $n)] ,'", "",
""]';
}
For more information on rand(), see the Manual:
http://www.php.net/rand
Cheers,
NC
[Back to original message]
|