I want to create my own custom config data in the application section of Codeigniter, but was wondering if we can build two dimensional config arrays.
Example of application/config/myconfig.php:
$myconfigarray = array('row1'=> array( 'col1'=>'col1val',
'col2'=>'col2val',
'col3'=>'col3val' ),
'row2'=> array( 'col1'=>'col1val',
'col2'=>'col2val',
'col3'=>'col3val' ));
Currently by default at least, Codeigniter only seems to support one dimensional config arrays. How can I use multidimensional arrays?
You can have configuration arrays in any size shape or form. Getting them to work entirely depends on what you want to do with them, how you’re loading them, and how you’re reading them.
I think your problem is that you need to rename
$myconfigarrayto$config:So for your example, let’s say the file is called
myconfig.php:This would print:
If you need to access a certain index, you’d have to do something like this:
If you happen to be running PHP 5.4 you can access it like so: