Scott87 Posted February 13, 2009 Share Posted February 13, 2009 I have php file which displays images based on what the page name is in the URL. the code is: <?php $rightbox = array( 'faqs' => '_img/faqanswers.jpg', 'contact-us' => '_img/contactsuccessful.jpg', 'login' => '_img/loginexperience.jpg', ); $page = isset($_GET['page']) ? $_GET['page'] : 'home'; // default to home page echo "<img src=\"{$rightbox[$page]}\" />"; ?> I'm trying to add more images to each section, like so: $rightbox = array( 'faqs' => '_img/faqanswers.jpg', 'contact-us' => '_img/contactsuccessful.jpg', '_img/contactpotential.jpg', '_img/contactwinner.jpg', 'login' => '_img/loginexperience.jpg', ); Obviously without any luck, how would I go about inserting the extra images into the code? Cheers Quote Link to comment Share on other sites More sharing options...
metrostars Posted February 13, 2009 Share Posted February 13, 2009 You could either make each image a different contact us: $rightbox = array( 'faqs' => '_img/faqanswers.jpg', 'contact-us' => '_img/contactsuccessful.jpg', 'contact-us2' => '_img/contactpotential.jpg', 'contact-us3' => '_img/contactwinner.jpg', 'login' => '_img/loginexperience.jpg', ); or a multidimensional array: $rightbox = array( 'faqs' => '_img/faqanswers.jpg', 'contact-us' => array('1' => '_img/contactsuccessful.jpg', '2' => '_img/contactpotential.jpg', '3' => '_img/contactwinner.jpg'), 'login' => '_img/loginexperience.jpg', ); Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted February 13, 2009 Share Posted February 13, 2009 Not sure exactly what you're trying to achieve: multiple images for each page <?php $rightbox = array( 'faqs' => '_img/faqanswers.jpg', 'contact-us' => array('_img/contactsuccessful.jpg', '_img/contactpotential.jpg', '_img/contactwinner.jpg'), 'login' => '_img/loginexperience.jpg', ); $page = isset($_GET['page']) ? $_GET['page'] : 'home'; // default to home page foreach($rightbox[$page] as $pageImage) echo "<img src=\"{$pageImage}\" />"; } ?> or new pages: $rightbox = array( 'faqs' => '_img/faqanswers.jpg', 'contact-us' => '_img/contactsuccessful.jpg', 'contact-potential' => '_img/contactpotential.jpg', 'contact-winner' => '_img/contactwinner.jpg', 'login' => '_img/loginexperience.jpg', ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.