11Tami Posted January 14, 2008 Share Posted January 14, 2008 Hello, how can I include two PHP variables in an image src, depending on which variable I will be using at the time? For example: <?php $image[1] = "http://store.officeworld.com/ProductImages/united/standard/MOW36113_1_1.JPG"; $image[2] = "https://store.officeworld.com/productimages/united/thumbnails/HAM122549_1_1_100.jpg"; $image[4] = "https://store.officeworld.com/productimages/united/thumbnails/A0001856.JPG"; $image[5] = "https://store.officeworld.com/productimages/united/thumbnails/HEWQ1396A_1_1_100.jpg"; $get1 = rand(1,2); $get2 = rand(3,4); echo "<img src='$image[$get1($get2)]' >"; ?> This following part from the above script I need help with: echo "<img src='$image[$get1($get2)]' >"; Sometimes I will only be using $get1 from the array, and other times I will only be using $get2 from the array, depending on what a database inserts into the image source. How can I have the src hold both $get1 and $get2 variables at the same time? The way I have it above says it cannot hold both. Please let me know, thank you very much. Link to comment https://forums.phpfreaks.com/topic/86027-two-variables-in-on-field/ Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 Only hold one variable like $picture and let something else dictate if $picture = $image[$get1] or $picture = $image[$get2] Then you can just do echo "<img src=$picture >"; Link to comment https://forums.phpfreaks.com/topic/86027-two-variables-in-on-field/#findComment-439300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.