Re: FN-FORUM: Adding to a multidimensional array in php
date posted 4th January 2007 14:26
As php arrays are "associative" arrays, you could simply use the
following (which you can see running at:
http://rubiconcsl.com/testarray.php : -
function dp just does a pretty printout of variables :)
Hope this helps. If so, my invoice will be in the post :)
--
Dominic Raywood
Rubicon Computer Services Limited
W: http://rubiconcsl.com
E: [EMAIL REMOVED]
T: 08456 521 561 (+44 1823 698420)
M: 07050 204 998 (+44 7811 252573)
Duncan Glendinning wrote:
>
> 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
>