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 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]


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

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