Home >>PHP Array Functions >PHP array_change_key_case() Function

PHP array_change_key_case() Function

PHP array_change_key_case() Function

PHP array_change_key_case() function is used to change case of all of the keys present in a given array either to lower case or upper case. It accepts two parameters out of which one is required and the other is optional. It returns an array as output with the changed case of the key, either to lowercase or to upper case.

Syntax:

array_change_key_case($array, $case);

Parameter Values

Parameter Description
array This is a required parameter. This parameter defines the array to use.
case This is an optional parameter. This parameter defines the case of the array.

Here is an example of array_change_key_case() function in PHP:

<html>
<body>
<pre>
<?php
$a=array("Jerry"=>"Noida","Abhi"=>"Delhi","Mickey"=>"Haryana");
print_r(array_change_key_case($a));
?>
</pre>
</body>
</html>
Output:

Array
(
    [jerry] => Noida
    [abhi] => Delhi
    [mickey] => Haryana
)

Example 2:

<html>
<body>
<pre>
<?php
$a=array("Jerry"=>"Noida","Abhi"=>"Delhi","Mickey"=>"Haryana");
print_r(array_change_key_case($a,CASE_UPPER));
?>
</pre>
</body>
</html>
Output:
Array
(
    [JERRY] => Noida
    [ABHI] => Delhi
    [MICKEY] => Haryana
)

No Sidebar ads