|
Posted by Steve on 09/27/07 21:27
"RageARC" <ragearc@gmail.com> wrote in message
news:1190927871.534459.223320@22g2000hsm.googlegroups.com...
> On 27 Sep, 21:50, "Steve" <no....@example.com> wrote:
>> "RageARC" <rage...@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.
>
> foreach ($array['JOHN']['VALUE2'] as $value2) {
> print $value2;
> }
>
> print $array['JOHN']['VALUE1'][0];
> print $array['JOHN']['VALUE2'][0];
no, no...using his data...ALL of it. then iterate the array cleanly showing:
john
red
45
56
yellow
11
mike
blue
23
black
41
what you've shown is the sample data YOU wanted. the op doesn't know how to
set up HIS data properly into an array. YOUR data and example will lead to
HIS code not working when implemented.
now, try again.
[Back to original message]
|