My name is Shruti.I’m new to php. I have a program which displays images randomly, there are about 200 images in my program.I want to display the random images with out repetition, can any one please help with this. here is my code.
Appreciate your help
Thank you.
I don’t know whats about the
$img_idbut you could consider to useshuffle().But then you loose the connection to
$img_id. You could (I am not sure if this is the best solution), build your array this way:In the long run, it is probably better to store all the image paths in a CSV file or even a database. Believe me, you don’t want to maintain an array with > 200 entries manually 😉
You can loop over images this way (they are in random order now):
If you only want to display a subset of the images, randomly chosen, you can do this:
Some comments on your code:
$rancontains a key randomly chosen from the images.You always pick the same entry from
$file_arrayand$image_idbecause you never change$ran. That is way you get the same image 200 times.