Forum Moderators: coopster

Message Too Old, No Replies

How to access array key

         

devitnow

9:22 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



I'm trying to use the array_key() function, but I'm having no luck.

I have an array that prints out like this:

Array (
[1] => 1956.0688881835
[2] => 1998.9853287785
[3] => 1839.565611694
[5] => 1900.3659881069
[25] => 59.368599722285
[37] => 197.68427334405
)

The index represents a recordset ID

You can I access just '37' for example?

thank you

jatar_k

11:23 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



echo $array[37];

is that what you mean?

>> array_key

do you mean array_keys?

I don't understand what you are looking for.

devitnow

3:18 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Hi There,

thanks for your help again. Here's what I have,

As the mySQL select statement loops through a query looking for locations, this line here populates the array:

$nearest_location[$location_id] = $location_distance;

$location_id is the record ID, that I have put into the key.

I want to pull out just key so that I can use it later in the script.

I know how to do something like:

echo $nearest_location[]; or
echo $nearest_location[3]; which will show $location_distance, but I want to echo just the key which is the value stored by $location_id

thanks again

jatar_k

5:55 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe try the example on this page
[php.net...]