fellixombc Posted February 23, 2009 Share Posted February 23, 2009 Its echoing out a '1' one the homepage..and every other page..not what the variables say.. website: http://webdevshare.com here is my script i wrote... please help? <?php ############################### ##Copyright(C)Webdevshare.com## ############################### $home = "hello, homepage"; //start of home content //end of home content $tutorials = "tutorials!"; // start of tutorials content //end of tutorials content $memberships = "memberships!!! XD"; // Start of memberships content // end of memberships content $downloads = "downloads lul"; //Start of downloads content //end of downloads content $chat = "chatting ftw?"; // Start of chat box //End of chat box $pages = array ( array($choice => $home, 'url' => '/'), array($choice => $tutorials, 'url' => '/tutorials.php'), array($choice => $memberships, 'url' => '/memberships.php'), array('choice' => '$downloads', 'url' => '/downloads.php'), array('choice' => '$chat', 'url' => '/chat.php') ); $currentpage = $_SERVER['REQUEST_URI']; foreach($pages as $page) { $choice = ($page['url'] == $currentpage); echo $choice; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146441-solved-echoing-and-array-help/ Share on other sites More sharing options...
btherl Posted February 23, 2009 Share Posted February 23, 2009 I think you need to spend more time on the basics of php. Play around a bit using this code: print "<pre>"; var_dump($pages); print "</pre>"; That will show you the contents of any variable ($pages in this case). You should do the same for $currentpage, so you can see what you are comparing against. This line: $choice = ($page['url'] == $currentpage); says "Compare $page['url'] and $currentpage. If they are equal, set $choice to true. Otherwise set it to false" When you try to print out "true", that's when you see 1. Instead you should be printing something from $page, eg "echo $page['choice']" or "echo $page['url']" Quote Link to comment https://forums.phpfreaks.com/topic/146441-solved-echoing-and-array-help/#findComment-768830 Share on other sites More sharing options...
fellixombc Posted February 23, 2009 Author Share Posted February 23, 2009 I think you need to spend more time on the basics of php. Play around a bit using this code: print "<pre>"; var_dump($pages); print "</pre>"; That will show you the contents of any variable ($pages in this case). You should do the same for $currentpage, so you can see what you are comparing against. This line: $choice = ($page['url'] == $currentpage); says "Compare $page['url'] and $currentpage. If they are equal, set $choice to true. Otherwise set it to false" When you try to print out "true", that's when you see 1. Instead you should be printing something from $page, eg "echo $page['choice']" or "echo $page['url']" Ill give that a try, and sorry, I've just started learning php..and kinda went head in =/ Quote Link to comment https://forums.phpfreaks.com/topic/146441-solved-echoing-and-array-help/#findComment-768832 Share on other sites More sharing options...
fellixombc Posted February 23, 2009 Author Share Posted February 23, 2009 Alright, it works fine now, but its echoing out the other variables =/, how can i stop this and make it only print out the $home when its home etc,. Quote Link to comment https://forums.phpfreaks.com/topic/146441-solved-echoing-and-array-help/#findComment-768835 Share on other sites More sharing options...
btherl Posted February 23, 2009 Share Posted February 23, 2009 Can you describe what you are trying to do? Are you trying to use the url of the page (eg '/tutorials.php') to determine which page you shoudl display? Quote Link to comment https://forums.phpfreaks.com/topic/146441-solved-echoing-and-array-help/#findComment-768919 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.