garry Posted May 30, 2008 Share Posted May 30, 2008 So I have a function to add the header to my site called add_header. This will add a file called header.php to the document I have a menu in the header and I want to use an if ($variable == 'somepage') { change the id } This would change the id of the menu so that the current page is a different color. The problem is, even if I add the $variable at the top of the page, it is not available within the function and I get an error. Is there any way to fix this? Thanks Link to comment https://forums.phpfreaks.com/topic/107938-solved-variables-outside-of-functions/ Share on other sites More sharing options...
BillyBoB Posted May 30, 2008 Share Posted May 30, 2008 Send the variable with the function. EX: function addHeader($title) { //add menu stuff here } Then when you are calling on the function just insert the info there. EX: addHeader("somepage") Link to comment https://forums.phpfreaks.com/topic/107938-solved-variables-outside-of-functions/#findComment-553275 Share on other sites More sharing options...
garry Posted May 30, 2008 Author Share Posted May 30, 2008 Ah worked great, thanks Link to comment https://forums.phpfreaks.com/topic/107938-solved-variables-outside-of-functions/#findComment-553279 Share on other sites More sharing options...
BillyBoB Posted May 30, 2008 Share Posted May 30, 2008 No problem make sure to press the solved button at the bottom of the post. Link to comment https://forums.phpfreaks.com/topic/107938-solved-variables-outside-of-functions/#findComment-553281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.