Newbie Question on Accessing Arrays via Index Key
am 24.09.2007 22:52:53 von Vik RubenfeldI've got an multi-dimensional array that looks like this, when I examine
it in the Zend Debugger:
[]$ArrayOfData = Array[15]
[]1001 = Array[12]
tin = (double) 0.032
iron = (double) 101.24
Alloy_ID = (strin:4) 1001
,,,
[]1019 = Array[12]
tin = (double) 4.49
iron = (double) 53.03
Alloy_ID = (strin:4) 1019
...
Etc. I want to add a new field to each sub-array. For various reasons,
I can't use ForEach; I need to access the sub-arrays by their index key.
I tried doing this:
$theKey = 1001;
data_for_new_field = "55";
$ArrayOfData[$theKey]['new_field'] = $data_for_new_field;
But, that just added a new array element to $ ArrayOfData, like this:
[]$ArrayOfData = Array[15]
[]"1001" = Array [1]
new_field = (string:2) 55;
[]1001 = Array[12]
tin = (double) 0.032
iron = (double) 101.24
Alloy_ID = (strin:4) 1001
,,,
[]1019 = Array[12]
tin = (double) 4.49
iron = (double) 53.03
Alloy_ID = (strin:4) 1019
...
What's the correct way to access elements in $ArrayOfData, by their
index key?
Thanks very much in advance to all for any info.