Re: How do I get the first element's key of an array of objects?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux