You are here: Newbie Question on Accessing Arrays via Index Key « PHP Programming Language « IT news, forums, messages
Newbie Question on Accessing Arrays via Index Key

Posted by Vik Rubenfeld on 09/24/07 20:52

I'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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация