RE: [PHP] array question
| From: | Ford, Mike [LSS] | Date: | Mon, 10 Mar 2003 16:03:25 +0000 |
| Subject: | RE: [PHP] array question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-138967@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jason Wong [mailto:php-general@gremlins.biz]
> Sent: 10 March 2003 15:35
> To: php-general@lists.php.net
> Subject: Re: [PHP] array question
>
>
> On Monday 10 March 2003 21:13, Diana Castillo wrote:
> > If I sort an array, and now the keys are not in numerical
> order, how can I
> > get the key of the first element?
> > If I do array_shift I get the first element but I want that key.
>
> Not very elegant -- there must be a better way?
>
> foreach ($doo as $key => $value) {
> print "Key:$key Value:$value";
> break;
> }
How about
reset($doo);
$first_key = key($doo);
?
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211