Randomising dir reading

Hi,

I have a gallery script that requires a list of files which I’m calling in using a fairly simple php dir reading:

<?php 
$galleryfolder= getcwd().'/images/galleries/'.$row_thispage['galleryfolder'].''
$images = dir($galleryfolder);
//loop through images
while (($file = $images->read()) !== false)
{
//SNIP - irrelevant stuff happening to display the pictures etc
}
?>

I’d really like to be able to randomise the resulting list of images, but I can’t think of a way to do it… anyone got any clever ideas?

Thanks

Save all the images to an array, randomise that, then display.

and to help… if your dir() becomes a scandir(), you’ve got half of Anthony’s suggestion done…

thanks people, I’ll let you know how I get on…

THat was fairly painless!

<?php  
$galleryfolder= getcwd().'/images/galleries/'.$row_thispage['galleryfolder'].'' 
$images = scandir($galleryfolder);
if ($row_thispage['slidesrandom']==1){shuffle($images);}
//loop through images 
foreach ($images as $file) 
{ 
//SNIP - irrelevant stuff happening to display the pictures etc 
} 
?>

sorted!