plutomed Posted October 22, 2007 Share Posted October 22, 2007 I have an array with some bits in and it don't echo out properly. $footer = array( "names" => array("About Us", "Site Map", "Privacy Policy", "Contact Us"), "pages" => array(prefix()."index.php?pm=about_us", prefix()."index.php?pm=site_map", "javascript:win_open('".prefix()."includes/privacy_policy.php', 'Privacy_policy', 'directories=0, height=200, location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=0, width=500');", prefix()."index.php?pm=contact_us") ); $count_footer = count($footer['names']); $i_footer = 0; while($i_footer < $count_footer) { $links_footer .= " <a href=\"".$footer['pages'][$i_footer]."\">".$footer['names'][$i_footer]."</a> |"; $i_footer++; } echo $links_footer; This is what it echo's: /new//new//new//new/ About Us | Site Map | Privacy Policy | Contact Us | The prefix is in the wrong place. How come? Link to comment https://forums.phpfreaks.com/topic/74312-solved-arrays/ Share on other sites More sharing options...
kenrbnsn Posted October 22, 2007 Share Posted October 22, 2007 Can you post the script for your "prefix" function? Ken Link to comment https://forums.phpfreaks.com/topic/74312-solved-arrays/#findComment-375460 Share on other sites More sharing options...
plutomed Posted October 22, 2007 Author Share Posted October 22, 2007 it just says echo "/new/"; Link to comment https://forums.phpfreaks.com/topic/74312-solved-arrays/#findComment-375461 Share on other sites More sharing options...
kenrbnsn Posted October 22, 2007 Share Posted October 22, 2007 That is why. When you "echo" a string it goes directly to the browser screen, you need to return the string if you want to have it put into the string. Write it something like this: <?php function prefix() { return ('/new/'); } ?> BTW, I tightened up your code a little: <?php $footer = array("names" => array("About Us", "Site Map", "Privacy Policy", "Contact Us"), "pages" => array(prefix()."index.php?pm=about_us", prefix()."index.php?pm=site_map", "javascript:win_open('".prefix()."includes/privacy_policy.php', 'Privacy_policy', 'directories=0, height=200, location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=0, width=500');", prefix()."index.php?pm=contact_us")); $count_footer = count($footer['names']); $i_footer = 0; $tmp = array(); for ($i_footer=0;$i_footer<count($footer['names']);$i_footer++) $tmp[] = ' <a href="' . $footer['pages'][$i_footer] . '">' . $footer['names'][$i_footer] . '</a>'; echo implode(' | ',$tmp); ?> Using an array to temporarily store the footer string and then using the implode function puts the " | " between the entries and you don't have a trailing " | ". Ken Link to comment https://forums.phpfreaks.com/topic/74312-solved-arrays/#findComment-375470 Share on other sites More sharing options...
plutomed Posted October 22, 2007 Author Share Posted October 22, 2007 Ah ok thanx. And thanx for the cleaning the code but use the other "|" at the end coz I cut the bit of code out that wasn't relevent. Link to comment https://forums.phpfreaks.com/topic/74312-solved-arrays/#findComment-375472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.