FN-FORUM: Adding to a multidimensional array in php
date posted 4th January 2007 13:48
Afternoon all,
Am stuck on this silly thing, and hoping someone can help. As an example:
I have an initial multidimensional array set up as follows:
$data = array(
array('one'=>'A', 'two'=>'B', 'three'=>'C'),
array('one'=>'a', 'two'=>'b', 'three'=>'c')
);
Then I have a for loop which initialises a 1 dimensional array, and
adds it to the array above
for ($i=0; $i < 5; $i++) {
$TempData = array('one'=>'1', 'two'=>'2', 'three'=>'3')
array_push($data,array($TempData));
}
If the data for the 2 dimensional array I wanted was in table format,
it would look like this
A B C
a b c
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
For some reason though, I can't add to the 2-dim array with the for
loop. What am I doing wrong?
Thanks,
D