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

From: Date: Fri, 08 Apr 2005 15:53:07 +0000
Subject: RE: [PHP] How do I get the first element's key of an array of objects?
Groups: php.general 
Request: Send a blank email to php-general+get-212648@lists.php.net to get a copy of this message
Mattias Thorslund <mailto:mattias@inreach.com> on Thursday, April 07, 2005 5:20 PM said: >> <?php >> >> $keys = array_keys($object_array); >> >> $first_key = $keys[0]; > > I wonder if that will work, when the first element has the key 3... ? > > This might work better: > > $keys = array_keys($object_array); > $first_key = reset($keys); Read www.php.net/array_keys and you shall have your answer. From the php docs: <?php $array = array(0 => 100, "color" => "red"); print_r(array_keys($array)); ?> Will output. Array ( [0] => 0 [1] => color ) Chris.

« previous php.general (#212648) next »