PHP array_change_key_case() Function

6 Jan 2025 | 1 min read

It is an inbuilt function of PHP. The array_change_key_case() function returns an array with all arrays keys in lower case or upper case.

Syntax

ParameterDescriptionIs compulsory
arraySpecifies the array to usecompulsory
caseCase to use(Upper or Lower)optional

Important Note: If the second parameter is avoided then by default the keys of array will get converted to lowercase.

Example 1

Output:

 Array( [A]=>a [E]=>e [I]=>i [O]=>o [U]=>u ) 

Example 2

Output:

 Array ( [rahul]=> 10000 [ajay]=> 15000 [sid]=> 20000 ) 

Example 3

If two or more array keys will be the same after running array_change_key_case( ) function, the latest array will override the other.

Output:

 Array ([A]=> Agra [B]=> Bengaluru [C]=> Chennai ) 

Example 4

If we ignore the second parameter in the function array_change_key_case( ) then the keys will be converted to lowercase.

Output:

 Array ([rahul]=> 10 [vikas]=> 20 [sid]=> 25 )