tazeha Posted February 10, 2014 Share Posted February 10, 2014 (edited) 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 February 10, 2014 by tazeha Link to comment Share on other sites More sharing options...
justsomeguy Posted February 10, 2014 Share Posted February 10, 2014 What's not working correctly? You may want to use this instead: http://www.php.net/manual/en/function.array-rand.php 1 Link to comment Share on other sites More sharing options...
thescientist Posted February 11, 2014 Share Posted February 11, 2014 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now