Jump to content

How display random photo with text?


tazeha

Recommended Posts

I have to display random photo using array and rand function.

Now I would add text under each photo(For example, the words of the elders text with image)

my code:

What do I do?


<?php$images=array(    array('file'=>'pic1','alt'=>"Your Description About pic1"),    array('file'=>'pic2','alt'=>"Your Description About pic2"),    array('file'=>'pic3','alt'=>"Your Description About pic3"),    array('file'=>'pic4','alt'=>"Your Description About pic4"),    array('file'=>'pic5','alt'=>"Your Description About pic5"),    array('file'=>'pic6','alt'=>"Your Description About pic6"),    )    $i=rand(0,count($images)-1);    $selectimage="newfolder/{$images[$i]['file']}.jpg";    $alt=$images[$i]['alt']; if (file_exists($selectimage) && is_readable($selectimage))    $imagesize= getimagesize($selectimage);?>

view in html

<img src="<?php echo $selectimage;?> "  alt="<?php echo $alt ; ?>" <?php echo $imagesize[3] ; ?> /> 
Edited by tazeha
Link to comment
Share on other sites

are you asking how to add a third member to each array, like a description?

 

If so, just follow the convention you are using for src and alt, and just make a third member, called desc. or something. get it from the randomly selected index (like with src and alt), and put it in a <p> tag or something equivalent below the output the image.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...