lundi 5 décembre 2016

Random image with caption

I have a series of images - image1 to image12. I use PHP to randomly generate the number, resulting in a random image once the page loads.

url('img/home/hero-img/hero-img-<?php echo rand(1, 12) ?>.jpg')

Each image has a caption like "This is a sunflower".

I am trying to say that if the random number is x then the caption generated should refer to x

Is it a better idea to use a 2D array to store captions and images? That way when an image is selected the caption should be correct.




Aucun commentaire:

Enregistrer un commentaire