The array_change_key_case()
function
changes all keys in an array to lowercase or uppercase.
PHP array_change_key_case() function has the following syntax.
array_change_key_case(array,case);
Parameter | Is Required | Description |
---|---|---|
array | Required. | Specifies the array to use |
case | Optional. | Case to use |
Possible values for case:
Value | Meaning |
---|---|
CASE_LOWER | Default value. Changes the keys to lowercase |
CASE_UPPER | Changes the keys to uppercase |
array_change_key_case() function returns an array with its keys in lowercase or uppercase, or FALSE if array is not an array.
Change the lowercase key to uppercase.
<?php
$age=array("a"=>"a","b"=>"b","c"=>"c");
print_r(array_change_key_case($age,CASE_UPPER));
?>
The code above generates the following result.
If two or more keys will be equal after running array_change_key_case() (e.g. "b" and "B"), the latest array will override the other.
<?php
$pets=array("a"=>"a","b"=>"b","B"=>"B","A"=>"A");
print_r(array_change_key_case($pets,CASE_UPPER));
?>
The code above generates the following result.