Page 1 of 1

[SOLVED] obtaining the index order of a key in an associate

Posted: Mon Jun 21, 2004 6:47 pm
by davidklonski
Hi

assuming I have the following array:

Code: Select all

$arr = Array("bob" => "aaa", "alice" => "bbb");
Now assuming that I have a variable holding a name of a key in the array, for example:

Code: Select all

$var = "alice";
How can I find the numeric order of that key in the array.
I.e. "bob" is the first key, so its order is 0, "alice" is 1,...

thanks in advance

Posted: Mon Jun 21, 2004 7:06 pm
by feyd

Code: Select all

array_search($var, keys($arr));
or similar, I think.

Posted: Mon Jun 21, 2004 7:54 pm
by davidklonski
you are right.
Stupid me.

thanks