|
Posted by RageARC on 09/27/07 20:33
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.
> The idea as you can see is to have value1 and value2 as separate array
> within the name array.
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')
),
[...,]
);
Your way is similar to mine, but my second value is not inside the
first value ;) They are in different arrays.
Navigation:
[Reply to this message]
|