Organizational Research By

Surprising Reserch Topic

array_change_key_case — Changes the case of all keys in an array


#1 array_change_key_case() example

$input_array = array("FirSt" => 1, "SecOnd" => 4);
print_r(array_change_key_case($input_array, CASE_UPPER));
?>
The above example will output:

Array
(
    [FIRST] => 1
    [SECOND] => 4
)

asked May 25, 2015 in PHP by rahulgii
0 votes
28 views



Related Hot Questions

1 Answer

0 votes
Unicode example;

function array_change_key_case_unicode($arr, $c = CASE_LOWER) {
    $c = ($c == CASE_LOWER) ? MB_CASE_LOWER : MB_CASE_UPPER;
    foreach ($arr as $k => $v) {
        $ret[mb_convert_case($k, $c, "UTF-8")] = $v;
    }
    return $ret;
}

$arr = array("FirSt" => 1, "yağ" => "Oil", "şekER" => "sugar");
print_r(array_change_key_case($arr, CASE_UPPER));
print_r(array_change_key_case_unicode($arr, CASE_UPPER));
?>

Array
(
    [FIRST] => 1
    [YAğ] => Oil
    [şEKER] => sugar
)
Array
(
    [FIRST] => 1
    [YAĞ] => Oil
    [ŞEKER] => sugar
)
answered May 25, 2015 by rahulgii

...