Reply to Re: multidimensional array of arrays

Your name:

Reply:


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

"RageARC" <ragearc@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>';
}
}
}

[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

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