Reply to Re: [PHP] 2 dimensional array processing

Your name:

Reply:


Posted by Brent Baisley on 10/04/77 11:05

You've created a 2x2 array, not a 1x4, which might be confusing you:
tab2 ["fields1"] ["fields5"]
tab1 ["fields2"] ["fields7"]

You almost have it, you just need to set your loop up to handle
unlimited field/value pairs in your array.

One option is to structure your loop like this:
foreach ($insert as $table => $fields) {
foreach($fields as $field => $value) {
$fieldValuePairs[] = "$field = $value";
}
$fieldValueStr = implode(',', $fieldValuePairs);
echo "update $table set $fieldValueStr";
unset($fieldValuePairs);
}

On Jan 11, 2005, at 6:22 AM, Benjamin Edwards wrote:

> If I create the following 2 dimensional associative array:-
>
> $insert["tab2"]["fields1"] = "value1";
> $insert["tab1"]["fields2"] = "value2";
> $insert["tab2"]["fields5"] = "value3";
> $insert["tab1"]["fields7"] = "value4";
>
> how do I do 2 levels of nested loop with the first level looping
> through the first level of the array and the second nesting through
> the second. something like:-
>
> foreach( $insert as $table => $fields ) {
> foreatch( $fields as $field => $value ) {
> echo "update $table set $field = $value";
> }
> }
>
> Regards,
> Ben
>
>
>
>
>
>
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

[Back to original 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

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