Search code examples
phpglobshuffle

Foreach loop shuffled on output


Is there a simple way to get the result of this foreach loop shuffled on output at each page load?

foreach(glob('images/fotoalbum/*.*') as $file)

Solution

  • you can't shuffle after output but you can before.

    try this

    $dir=glob('images/fotoalbum/*.*');
    shuffle($dir);
    foreach($dir as $file){
    //operation here
    }