php - Random order of readdir -


how modify php code below output files in directory, put them in random order changes each time page gets reloaded?

if ($handle = opendir("files/slideshow/")) {     while (false !== ($slide = readdir($handle))) {         if ($slide != "." && $slide != "..") {             echo "<img style=\"background:url('/files/slideshow/{$slide}');background-repeat:no-repeat;\" src=\"/files/images/i.png\"/>";             $value = "1";         }     }     closedir($handle); } 

use more shorter way glob adding array shuffle.

$files = glob('files/slideshow/*'); // or 'files/slideshow/*.png' shuffle($files);  foreach ($files $slide)     {     echo "<img style=\"background:url('/files/slideshow/{$slide}');background-repeat:no-repeat;\" src=\"/files/images/i.png\"/>";     $value = "1";     } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -