i have a directory with 1000+ images and piece of code (by codaddict) which selects only first 10 and display it:
<?php
foreach (array_slice(glob("/directory/*.jpg"),0,10) as $path)
?>
ok this works, but i need to select 10 RANDOM images, not the first 10
yes, i can use shuffle first, then slice, but with 1000+ (or 10k+) images, it's not smart to shuffle long arrays just for 10 images, or maybe it is?
also, 2nd problem is that this is not just for one folder with 1000+ images, i need to use this script in other folders too, and some of them will only have 1 image, so i don't want to see errors if there is less than 10 images in a folder
i saw in php manual code for 2 random items, but i won't know how many images will be in folders - 1, 10, 10k... you see the problem
<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
?>
thanks!