Would anyone have a good example of a hard coded Multidimensional array using Codeigniter. The examples I've seen use a database, but I'm looking for an example that is hard coded.
Thanks
Greg
Would anyone have a good example of a hard coded Multidimensional array using Codeigniter. The examples I've seen use a database, but I'm looking for an example that is hard coded.
Thanks
Greg
$data = array('one' => array('sub1' => 42, 'sub2' => 90310),
'two' => array('sub1' => 321, 'sub2' => 10122));
Same thing with "short syntax"
$data = [
'one' => ['sub1' => 42, 'sub2' => 90310],
'two' => ['sub1' => 321, 'sub2' => 10122]
];
There are two types of array
Array like @DFriend answer
Array objects
use print_r($arrayName);
so that you can see the array structure.
For an example, let's say you getting result from the database. and if you use $result = $query->result();
you will get an array object and if you use $result = $query->result_array();
you will get 2D array.
those two array will be like below, (@DFriend example)
2D Array
$data = array('one' => array('sub1' => 42, 'sub2' => 90310),
'two' => array('sub1' => 321, 'sub2' => 10122));
Array Object link
Array (
[0] =>
stdClass Object
(
[id] => 25
[time] => 2014-01-16 16:35:17
[fname] => 4
[text] => 5
[url] => 6
),
[1] =>
stdClass Object
(
[id] => 25
[time] => 2014-01-17 16:35:17
[fname] => 45
[text] => 55
[url] => 66
)
)