RE: [PHP] Array Question
| From: | Ford, Mike [LSS] | Date: | Wed, 30 Oct 2002 11:09:24 +0000 |
| Subject: | RE: [PHP] Array Question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-122002@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: PHP List [mailto:php_list@ibcnetwork.net]
> Sent: 29 October 2002 17:20
> To: php
> Subject: Re: [PHP] Array Question
>
>
> No, array_keys does not do what I want, in order to user
> array_keys, it
> assumes I know the value of the key, but I don't,
Er -- no. Go read its definition again -- you *may* pass it a value for which you want the
corresponding keys, but by omitting the value argument you may also ask for *all* of the keys of
your array.
> I want to
> get the value of
> the key but all I know is the index.
First of all, I presume this means that, for example, if $index==4, you want to know what the key of
the 4th array element is?
In that case, the following, whilst not ideal, may be your best solution:
$keys = array_keys($array);
$required_key = $keys[$index];
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