You are here: Re: Need to capture only 5 random urls from a directory of hundreds « PHP Programming Language « IT news, forums, messages
Re: Need to capture only 5 random urls from a directory of hundreds

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация