PHP array_search() does this:
array_search()
Distorts the array for the given value and returns a successful key
I need a function that does the exact opposite, i.e. looks for an array for the given key and returns a successful value .
Is this even possible in PHP 5? If not, what solution would you suggest?
You can simply use the square bracket syntax as shown below:
$arr = array("key" => "value"); $v = $arr["key"]; // returns "value"
I'm confused. Does $array[$key] not work?
$array[$key]
To keep up with the PHP tradition
function array_search_reverse($needle, $haystack){ return $haystack[$needle]; }