goocharlton Posted July 12, 2007 Share Posted July 12, 2007 I am referring to this snippet of code: <?php if ('$left_column_' . $page_name == 0) echo ""; else include_once ("left_column.php"); ?> The problem I am having is in the second line of this code if ('$left_column_' . $page_name == 0) . I am trying to check if $left... has a 0 or not but I dont know how to include the $page_name variable inside the other variable. For example this is the complete code that I need to be functional: <?php $page_name = "Home"; $left_column_Home = "1"; if ('$left_column_' . $page_name == 0) echo ""; else include_once ("left_column.php"); ?> Link to comment https://forums.phpfreaks.com/topic/59715-solved-variable-inside-a-variable/ Share on other sites More sharing options...
per1os Posted July 12, 2007 Share Posted July 12, 2007 Your confusing yourself. <?php $pages = array("left_column" => array("home" => 1, "vacation" => 0), "right_column" => array("home" => 0)); if ($pages['left_column']['home'] == 0) echo ""; else include_once ("left_column.php"); ?> Something like that would be better. Link to comment https://forums.phpfreaks.com/topic/59715-solved-variable-inside-a-variable/#findComment-296779 Share on other sites More sharing options...
GingerRobot Posted July 12, 2007 Share Posted July 12, 2007 I think you're after the variable variable: <?php $page_name = "Home"; $left_column_Home = "1"; $var = 'left_column_'.$page_name; if ($$var == 0) echo ""; else include_once ("left_column.php"); Edit: Or ,as frost says, you could use arrays. Link to comment https://forums.phpfreaks.com/topic/59715-solved-variable-inside-a-variable/#findComment-296782 Share on other sites More sharing options...
sasa Posted July 12, 2007 Share Posted July 12, 2007 try <?php $page_name = "Home"; $left_column_Home = "0"; if (${'left_column_' . $page_name} == 0) echo "is 0"; else echo 'no 0'; //include_once ("left_column.php"); ?> Link to comment https://forums.phpfreaks.com/topic/59715-solved-variable-inside-a-variable/#findComment-296785 Share on other sites More sharing options...
goocharlton Posted July 12, 2007 Author Share Posted July 12, 2007 Thanks for your quick responses especially sasa, I used some of your idea your idea. I need the code in this..... <?php if (${'left_column_' . $page_name} == 0) ?> ....way because the 'if' function is in a template and the '$page_name' is at the top of that template page(which will have to be changes according to every page) but the '$left_column_Home' is in a separate site configuration file. I call that with include_once Link to comment https://forums.phpfreaks.com/topic/59715-solved-variable-inside-a-variable/#findComment-296790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.