BUCKHORN Posted September 26, 2013 Share Posted September 26, 2013 I know I can assign variables by using set or $config->var = something, but how do I set a configuration array? E.g. $config->site->theme Link to comment Share on other sites More sharing options...
Pete Posted September 26, 2013 Share Posted September 26, 2013 You could do: $config->var = array('item' => 'val', 'item2' => 'val2'); echo $config->var['item2']; Doesn't look as neat as you want, but should do the trick. Link to comment Share on other sites More sharing options...
interrobang Posted September 26, 2013 Share Posted September 26, 2013 I did a quick test and this seems to work too: $config->var = new stdClass(); $config->var->item = 'val1'; echo $config->var->item; 1 Link to comment Share on other sites More sharing options...
BUCKHORN Posted September 26, 2013 Author Share Posted September 26, 2013 Fantastic, thank you both! Link to comment Share on other sites More sharing options...
teppo Posted September 27, 2013 Share Posted September 27, 2013 Kind of pointing out the obvious, but the code Pete posted creates config ARRAY, while interrobangs approach creates OBJECT. It really doesn't matter which one you use here (especially considering that PHP array syntax isn't exactly pretty), just wanted to clarify the terminology a bit for any "OOP beginners" stumbling into this thread.. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now