Zepo. Posted October 14, 2007 Share Posted October 14, 2007 This doesnt work for some reason //Directory To You Style $config[theme] ='default'; //Style Initialization $config ='./theme/$config[theme]/html.php'; $config[html2] ='./theme/$config[theme]/html2.php'; include("./theme/$config[theme]/styleinfo.php"); Link to comment https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/ Share on other sites More sharing options...
LemonInflux Posted October 14, 2007 Share Posted October 14, 2007 shouldn't make a difference, but put inverted commas round the bracketed arrays: //Directory To You Style $config['theme'] ='default'; //Style Initialization $config ='./theme/$config[theme]/html.php'; $config['html2'] ='./theme/$config[theme]/html2.php'; include("./theme/$config[theme]/styleinfo.php"); Link to comment https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/#findComment-369406 Share on other sites More sharing options...
Zepo. Posted October 14, 2007 Author Share Posted October 14, 2007 Will do , have no idea why this simple thing isnt working =/ Link to comment https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/#findComment-369410 Share on other sites More sharing options...
Zepo. Posted October 14, 2007 Author Share Posted October 14, 2007 Do i have to put something around $config[theme] to make the variable to show instead of just that text? Link to comment https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/#findComment-369439 Share on other sites More sharing options...
GingerRobot Posted October 14, 2007 Share Posted October 14, 2007 Try: <?php $config['theme']='default'; //Style Initialization $config['html']='./theme/'.$config['theme'].'/html.php'; $config['html2']='./theme/'.$config['theme'].'/html2.php'; include('./theme/'.$config['theme'].'/styleinfo.php'); ?> You should quote array keys which are strings - otherwise you will recieve an undefined constant notice if you have error reporting set to include notices. Second, in your previous code you defined $config as an array (implicitly by using the key, 'them'), then changed it to a string, since you gave no key in this line: $config ='./theme/$config[theme]/html.php'; You then change it back to an array in the following line. The end result: an array with only one element. Lastly, strings inside single quotes are treated as literals. The following code: <?php $foo = 'bar'; echo '$foo'; ?> Produces the text: $foo - not the variables contents, bar. When echoing a variable, you either use concatenation(as i did - using the . to 'piece together' the bits of your string), or use double quotes. Link to comment https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/#findComment-369441 Share on other sites More sharing options...
kratsg Posted October 14, 2007 Share Posted October 14, 2007 Your problem is understanding the difference between a string and an array: //Directory To You Style $config[theme] ='default'; //Style Initialization $config ='./theme/$config[theme]/html.php'; $config[html2] ='./theme/$config[theme]/html2.php'; include("./theme/$config[theme]/styleinfo.php"); First, define $config as an array initially to deal with annoying php.ini files. Second, $config[theme] needs to have quotes around "theme" or else PHP will interpret that as another variable/undefined constant. So: $config = array(); $config['theme'] = 'default'; This part is fine. This means $config is defined as an array and that the index 'theme' is defined as 'default'. Now, look at your second part of the code: //Style Initialization $config ='./theme/$config[theme]/html.php'; $config[html2] ='./theme/$config[theme]/html2.php'; include("./theme/$config[theme]/styleinfo.php"); You want to store a string into a variable already defined as an array, this is a 'no-no'. Define another index of $config in order to make it work, IE $config['html']. Also put double quotes around the whole thing so it can be added into the thing correctly. //Style Initialization $config['html'] = "./theme/".$config['theme']."/html.php"; $config['html2'] = "./theme/".$config['theme']."/html2.php"; include("./theme/".$config['theme']."/styleinfo.php"); Finished code: $config = array(); $config['theme'] = 'default'; //Style Initialization $config['html'] = "./theme/".$config['theme']."/html.php"; $config['html2'] = "./theme/".$config['theme']."/html2.php"; include("./theme/".$config['theme']."/styleinfo.php"); Link to comment https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/#findComment-369442 Share on other sites More sharing options...
Zepo. Posted October 14, 2007 Author Share Posted October 14, 2007 Im slowly learning, thanks for the information. Link to comment https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/#findComment-369457 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.