Reply to Re: [PHP] How do I get the first element's key of an array of objects?

Your name:

Reply:


Posted by Chris Boget on 04/07/05 23:25

>> I don't see a graceful way of finding the first element's key ID.
>> Array
>> (
>> [3] => fooObject Object
>> (
>> [id:protected] => 3
>> [model:protected] => ABC
>> [read:protected] => public
>> [write:protected] => private
>> )
>> [5] => fooObject Object
>> (
>> [id:protected] => 5
>> [model:protected] => DEF
>> [read:protected] => public
>> [write:protected] => private
>> )
>> )
>> I want to get [3] somehow.
>> There has to be a better way. Something more elegant?
> How about reversing the array...
> http://us4.php.net/manual/en/function.array-reverse.php
> And then you can use array_pop()

Couldn't you also do something like this:

$key = current( reset( array_keys( $myArray )));

You probably don't really need the reset() I just put it in there
as an assurance.

thnx,
Chris

[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

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