|
Posted by Jerry Stuckle on 02/07/07 18:18
Rik wrote:
> Generale Cluster <alex@carrarosoftmasters.net> wrote:
>
>> Hello,
>> I have the following situation:
>>
>> $list[] is an array of MyElement objects.
>>
>> MyElement has two members: MyElement->member1; MyElement->member2;
>>
>> What I want is to get the following:
>>
>> $newlist[] so that:
>>
>> $newlist[0]=$list[0]->member2;
>> $newlist[1]=$list[1]->member2;
>> $newlist[2]=$list[2]->member2;
>> ...
>>
>> I need to do this using A SINGLE LINE OF CODE.
>> Is it possible? How to do this?
>
> Nothing _needs_ to be done in a single line of code, and for some
> actions you shouldn't even want it for readability.
>
>> I tried with:
>>
>> array_walk($list,create_function('$a,$b,$result','$result[] =
>> $a->member2;'), &$result);
>
> Tssk, single line, but a create_function()... That's cheating :P
>
> $newlist = array_map(create_function('$v','return $v->member2'),$list);
>
> --Rik Wasmus
Rik,
Sounds like a homework assignment to me... :-)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|