Jump to content

using arrays to dislay random stuff


real_illusions

Recommended Posts

Hi all,I have a simple script to display a random image, however, how can i make it so that image links to its own page?I was thinking of using multi-dimensional arrays, but i cant work out how to write it..This is what i have for the random image at the moment - <?php$randimg = array ('image.jpg', 'image2.jpg', 'image3.jpg');$random_key=array_rand($randimg,1);$file = "$randimg[$random_key]";echo ("<img alt=\"Random Image\" src=\"$file\" />")?>thanks:)

Link to comment
Share on other sites

you mean something like this?:

$images	= array(	array('image_1.jpg','page_1.php'),	array('image_2.jpg','page_2.php'),	array('image_3.jpg','page_3.php'),);$img	= array_rand($images);$image	= $img[0];$link	= $img[1];echo "<a href=\"$link\"><img src=\"$image\" /></a>";

Link to comment
Share on other sites

oh im sorry, not completly awake yet

$images	= array(	array('image_1.jpg','page_1.php'),	array('image_2.jpg','page_2.php'),	array('image_3.jpg','page_3.php'),);$rand	= array_rand($images); //or mt_rand(0,count($images)-1) might be faster, not sure$image	= $images[$rand][0];$link	= $images[$rand][1];echo "<a href=\"$link\"><img src=\"$image\" /></a>";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...