I have this code which works well:
function random_pic($dir = 'img')
{
$files = glob($dir . '/*.png');
$file = array_rand($files);
}
It grabs a random image from a directory. I have this in later:
<img src="<?php echo random_pic(); ?>"/>
<img src="<?php echo random_pic(); ?>"/>
Any way I can make it so it they both don’t display the same picture?
Try this:
array_rand can retrieve more then one key, just specify 2 as second parameter. In this case it returns am array.