Change Keys In Array To Lowercase Or Uppercase in Php

There are some scenerios in which we have to make our keys uppercase or lowecase. We have a function called array_change_key_case() to change our keys in an array to upper or lowercase. Let me show an example of it.

UpperCase

<!DOCTYPE html>
<html>
<body>

<?php
$array=array("India"=>"1","America"=>"2","Finland"=>"43");
echo "<pre>";
print_r(array_change_key_case($array,CASE_UPPER));
echo "</pre>";
?>

</body>
</html>

Result:

Array
(
    [INDIA] => 1
    [AMERICA] => 2
    [FINLAND] => 43
)

It was for the Uppercase scenerio when we need to do this for lowercase we only have to change the CASE_UPPER parameter to CASE_LOWER. All you keys will show in lower case.

LowerCase

<!DOCTYPE html>
<html>
<body>

<?php
$array=array("India"=>"1","America"=>"2","Finland"=>"43");
echo "<pre>";
print_r(array_change_key_case($array,CASE_LOWER));
echo "</pre>";
?>

</body>
</html>

Result:

Array
(
    [india] => 1
    [america] => 2
    [finland] => 43
)