|
Posted by Rik on 02/07/07 17:54
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]=3D$list[0]->member2;
> $newlist[1]=3D$list[1]->member2;
> $newlist[2]=3D$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 action=
s =
you shouldn't even want it for readability.
> I tried with:
>
> array_walk($list,create_function('$a,$b,$result','$result[] =3D =
> $a->member2;'), &$result);
Tssk, single line, but a create_function()... That's cheating :P
$newlist =3D array_map(create_function('$v','return $v->member2'),$list)=
;
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|