Reply to Re: Retrieving an object from an array

Your name:

Reply:


Posted by Ramon on 06/09/06 18:06

Thanks for your tips Colin!

greeting,
Ramon.


"Colin McKinnon"
<colin.thisisnotmysurname@ntlworld.deletemeunlessURaBot.com> wrote in
message news:Vhiig.23817$rC1.13515@newsfe4-gui.ntli.net...
> Ramon wrote:
>
>>
>> I've made two classes (see below): "Product" and "ProductList".
>> Class "Product" has some properties, including an ID prop to store it's
>> database ID.
>> Class "ProductList" contains an array of "Product" objects.
>>
>> My question is this:
>>
>> Is there some fancy way to retrieve a Product object from the
>> ProductList's object by it's ID-property, without looping through the
>> Products in the object array?
>> (Please note: I need to find it by a property value, not by it's array
>> index!)
>>
>
> Why not use the property value *as* the array index.
>
> <snip>
>> function add ($oProduct) {
>> $this->m_oProductList[] =& $oProduct;
>> }
>
> function add(&$oProduct, $id=false) {
> if ($id===false) {
> $id=$oProduct->m_iID;
> } else {
> $oProduct->m_iID->setID($id);
> }
> $this->m_oProduct[$id]=$oProduct;
> }
>
> (I think the reference operator is redundant - like Perl, PHP arrays only
> seem to hold scalars, so the value is assigned to the array by reference).
>
> HTH
>
> C.
>

[Back to original 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

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