You are here: Re: multidimensional array of arrays « PHP Programming Language « IT news, forums, messages
Re: multidimensional array of arrays

Posted by Steve on 09/27/07 20:50

"RageARC" <ragearc@gmail.com> wrote in message
news:1190925218.208985.247230@k79g2000hse.googlegroups.com...
> On 27 Sep, 21:27, "Steve" <no....@example.com> wrote:
>> "RageARC" <rage...@gmail.com> wrote in message
>>
>> news:1190923997.302334.233810@g4g2000hsf.googlegroups.com...
>>
>> > On 27 Sep, 20:58, JackpipE <pipe.j...@gmail.com> wrote:
>> >> name | value1 | value2
>> >> john | red | 45
>> >> john | red | 56
>> >> john | yellow | 11
>> >> mike | blue | 23
>> >> mike | black | 41
>> > $array = array(
>> > 'john' => array('VALUE1' => 'red', 'VALUE2' => '45'),
>> > [...]
>> > );
>>
>> actually, no, not based on his data.
>>
>> $array['john']['red'] = array(45, 56);
>> $array['john']['yellow'] = array(11);
>> $array['mike']['blue'] = array(23);
>> $array['mike']['black'] = array(41);
>>
>> to be completely literal about it. if coming from a db...
>>
>> $array = array();
>> foreach ($records as $record)
>> {
>> $array[$record['PERSON']][$record['COLOR'][] = $record['NUMBER'];
>>
>> }
>>
>> would build what we did by hand above. useage:
>>
>> foreach ($array as $person => $colors)
>> {
>> echo '<pre>+' . $person . '</pre>';
>> foreach ($colors as $color => $numbers)
>> {
>> echo '<pre> -- ' . $color. '</pre>';
>> foreach ($numbers as $number)
>> {
>> echo '<pre> -- ' . $number. '</pre>';
>> }
>> }
>>
>> }
>>
>>
>
> Sorry, but then we have different interpretations of the same.

yes...theres mine...which works. and yours...which doesn't correlate to the
sample data he gave...at all.

;^)

>> The idea as you can see is to have value1 and value2 as separate array
>> within the name array.

which may be well and good, however when you left out the fact that john
also likes yellow. further, you provide no direct association from the
values to the colors...unless you FORCE a for (...) iterator construct to
magically link them. shit, that's going to hurt when one of either the
parent or children are deleted from the array! you'll be looking to iterate
over sequencial keys...that could actually end up with gaping holes,
thinking, 'why the hell won't this work!'

> Inside NAME, one must have an array with VALUE1 and another with
> VALUE2. I admit that rereading now made it clearer for me. Let me
> reformulate:
>
> $array = array(
> 'john' => array(
> 'VALUE1' => array('red'),
> 'VALUE2' => array('45','56')
> ),
> [...,]
> );

yes, yes...now, reformulate again...to something that will work without
being contrived. ;^)

> Your way is similar to mine, but my second value is not inside the
> first value ;) They are in different arrays.

again, perhaps similar, but the important thing is...mine works. please,
provide your working example using EXACTLY this 're'formulation.

 

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

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