i have the following array which stores my photos
$photos = array(
"karate" => array('karate1.gif','karate2.png','karate3.gif','karate4.gif'),
"judo" => array("judo1.png","judo2.png","judo3.png","judo4.png"),
"kickboxing" => array("kb1.gif","kb2.png","kb3.gif","kb4.png")
);
and i have my function
function rndImage($category, $photos)
{
echo "<p>".count($photos[$category]);
$num = mt_rand(0, count($photos[$category])-1);
$varIMG = $photos[$category][$num];
echo $category." = ".$varIMG."<br />";
if(($key = array_search($varIMG, $photos[$category])) !== false)
{
array_splice($photos[$category], $key, 1);
}
echo count($photos[$category]);
return $varIMG."</p>";
}
now this works fine if i only call the function once, however if i call it several times on the page like so
rndImage("karate",$photos);
rndImage("karate",$photos);
rndImage("karate",$photos);
rndImage("judo",$photos);
rndImage("kickboxing",$photos);
i often get results where the image returned is the same like so
4karate = karate1.gif3
4karate = **karate3.gif**3
4karate = **karate3.gif**3
4judo = judo.png3
4kickboxing = kb1.gif3
its is removing the selected image from the array each time the function is ran but it resets each time the function is run too meaning duplicate images can be returned.
Is there a way i can keep a track on which images have been used and therefor not allow them to be chosen next time the function is run on that page?
any ideas would be greatly appreciated
Many Thanks