Hi,
Apologies if this is a total n00b question, but I’ve read the PHP manual on arrays and can’t get my brain around this.
If I have an array defined like this
[php]
$MyArr=array(
‘Fish’=>array(‘Fish1’=>‘Cod’,‘Fish2’=>‘Haddock’),
‘Cats’=>array(‘Cat1’=>‘Lion’,‘Cat2’=>‘Tiger’)
);
[/php]
and I loop through it like this
[php]Foreach($MyArr as $Sub){$Sub[‘Weird’]=‘Platypus’;}[/php]
I was expecting to see an item ‘Weird’ with the value ‘Platypus’ added to both the Fish array and the Cats array.
But when I use
[php]print_r($MyArr);[/php]
I just get
[php]Array ( [Fish] => Array ( [Fish1] => Cod [Fish2] => Haddock ) [Cats] => Array ( [Cat1] => Lion [Cat2] => Tiger ) ) [/php]
Can someone help me by explaining why the extra key-item paring hasn’t been added to the array and how I would achieve this?
Thank you.