You are here: Re: create array from members of an array of objects « PHP Programming Language « IT news, forums, messages
Re: create array from members of an array of objects

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]


Удаленная работа для программистов  •  Как заработать на 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

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