adding to a multi-dimensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

adding to a multi-dimensional array

Post by aceconcepts »

Hi,

I want to be able to add to this array:

Code: Select all

 
$patientTreatments=array($patientId=>$treatmentSelect);
 
Currently when I add one patient and mutiple treatments to this array it outputs correctly: Array ( [2] => Array ( [0] => 4 [1] => 11 ) )

The problem is when I try to addadditional values i.e. in a loop, it does not store all values, just one.

How does one add to this collection of arrays?
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: adding to a multi-dimensional array

Post by EverLearning »

Code: Select all

$patientTreatments[] = array($patientId=>$treatmentSelect);
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: adding to a multi-dimensional array

Post by aceconcepts »

Yeh, i tried that already.

I think i will need to re-think my logic.

Thanks.
Post Reply