RE: [PHP] um ... arrays
| From: | Edward Kay | Date: | Thu, 21 Dec 2006 14:01:55 +0000 |
| Subject: | RE: [PHP] um ... arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246123@lists.php.net to get a copy of this message | ||
$files is empty - nowhere in your while loop do you add any data to it.
My guess is your question is really 'Why are my images displayed in the same
order as the directory?'. This is because you're displaying them at the same
time as reading the dir. To randomise the order, add all the file names to
the $files array, shuffle($files) and then have a foreach loop to iterate
over $files and output the HTML to display them.
Edward
> -----Original Message-----
> From: Steven Macintyre [mailto:steven@steven.macintyre.name]
> Sent: 21 December 2006 13:45
> To: php-general@lists.php.net
> Subject: [PHP] um ... arrays
>
>
> Hi ...
>
> I have the following;
>
> $files = array();
> $curimage=0;
> if($handle = opendir($dirname)) {
> while(false !== ($file = readdir($handle))){
> if(eregi($pattern, $file)){
> $filedate=date ("M d, Y H:i:s",
> filemtime($file));
> if(substr($file,-5)=='t.jpg') {
> echo 'leftrightslide[' . $curimage .']=\'<a
> href="?file='.$file.'&c='.$cat.'"><img
> src="'.$dirname.'/'.$file.'"
> style="border:1px solid #bb3621"></a>\';' . "\n";
> }
> $curimage++;
> }
> }
>
> closedir($handle);
> }
> shuffle($files);
> return($files);
>
> now ... why does files not get shuffled?
>
> Is that not the purpose of that function ?
>
> Steven
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>