PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've been trying to get this for a few hours and can't seem to do it. Trying to select say 5 random images form a directory for a Gallery. I can sort them all fine, but rand() doesn't seem to work.
<?php
$list = array('foo.gif', 'bar.gif', 'baz.gif');
$random = array_rand($list, 2);
// $random now has 2 elements of the $list array
foreach ($random as $file) {
echo "xml.....$file";
}
?>
It returns an array and you try to use it as a string or int value as a key for an array. It therefore doesnt work as its not returning what you expect it to. As said before it returns an array and so must be treated as one - im sure you know how to do this as you do it already in your code:
Appreciate it rehfeld, I tried that and it didn't work for some reason with $list being the array. Output numbers. I think I've just been at it too long today, sorry for the rant.
I resorted to shuffle(). Works just as good, thanks!