Pjack125 Posted December 8, 2008 Share Posted December 8, 2008 I am trying to create a buttons by getting the information from two arrays one for the buttons URLS and the other one is for the buttons lable. How would i go about doing so. so far i have $array1 = array("lable1","lable2","lable3"); $array2 = array("URL1","URL2","URL3"); I tried using for for each but that gave me issues what is the most effective way to achieve this? Link to comment https://forums.phpfreaks.com/topic/136093-solved-creating-buttons-and-lables-with-two-arrays/ Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 for <?php $cnt = count($array1); for ($i=0; $i<$cnt; $i++) { echo '<a href="' . $array1[$i].'">' . $array2[$i] . '</a>'; } ?> Something like that should work. Edit: Or make it associative array: <?php $arrays = array("lable1"=>"URL1","lable2"=>"URL2", "lable3" => "URL3"); foreach ($arrays as $key => $val) { echo '<a href="' . $val.'">' . $key . '</a>'; } ?> Link to comment https://forums.phpfreaks.com/topic/136093-solved-creating-buttons-and-lables-with-two-arrays/#findComment-709631 Share on other sites More sharing options...
Maq Posted December 8, 2008 Share Posted December 8, 2008 Why can't you use a multi-dimensional array? Link to comment https://forums.phpfreaks.com/topic/136093-solved-creating-buttons-and-lables-with-two-arrays/#findComment-709635 Share on other sites More sharing options...
Pjack125 Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks I was just having a brain fart. I figured the first option out... finally but i do like the second one best though I'm new at this i like writing concise lines of code. THANKS Link to comment https://forums.phpfreaks.com/topic/136093-solved-creating-buttons-and-lables-with-two-arrays/#findComment-709646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.