PHP - Get key name of array value

Solution 1:

If you have a value and want to find the key, use array_search() like this:

$arr = array ('first' => 'a', 'second' => 'b', );
$key = array_search ('a', $arr);

$key will now contain the key for value 'a' (that is, 'first').

Solution 2:

key($arr);

will return the key value for the current array element

http://uk.php.net/manual/en/function.key.php