RE: FN-FORUM: Adding to a multidimensional array in php
date posted 4th January 2007 14:03
Maybe just try:
array_push($data, $TempData);
also, you do realise you're trying to add it five times to $data with that
loop?
-----Original Message-----
From: [EMAIL REMOVED] [EMAIL REMOVED] On Behalf Of Duncan
Glendinning
Sent: 04 January 2007 14:36
To: FN-FORUM / [EMAIL REMOVED]
Subject: FN-FORUM: Adding to a multidimensional array in php
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
--
Freelancers, contractors earn more with Prosperity4
Call 0870 870 4414 or visit www.prosperity4.com
and benefit from Inland Revenue approved expenses today.
To advertise here: http://www.freelancers.net/advertising.html