Skip to content

Look Up an Array Key

Look up a value by array key, with an optional case-insensitive search that still returns the original stored value.

Language: PHP

Added on: 18th August 2026

function array_key_search($haystack, $needle)
{
    if (isset($haystack["$needle"])) {
        return $haystack["$needle"];
    }
    return null;
}

function array_key_isearch($haystack, $needle)
{
    $haystack = array_change_key_case($haystack, CASE_LOWER);
    $needle = strtolower($needle);

    return array_key_search($haystack, $needle);
}