Skip to content

PHP Array Functions: array_change_key_case

Last updated on January 17, 2018

In this programming tutorial, you will learn how to use the PHP array function array_change_key_case to manipulate array keys in your arrays.

array_change_key_case() function is used to manipulate array keys(string) into UPPERCASE OR LOWERCASE.

Syntax:


array_change_key_case($array, CASE_LOWER or CASE_UPPER);

Here :
$array is the name of the array
The second parameter is manipulated type, means whether you are going to convert the values in the array to upper or lower case(default).

if you omit the second parameter, all keys are converted to lowercase, not numbers(Numbered indices are left as is).

Programming Example:

$name = array('A' => 'Arjun','S' => 'Sruthi','N' => 'Naveen');
print_r(array_change_key_case($name,CASE_LOWER));
//OUTPUT 
Array ( [a] => Arjun [s] => Sruthi [n] => Naveen ) 

The About Code take the $name array and change all the keys into lower case.

Converting array keys to upper case is simple one like above example just change the second parameter ,here is the example :

$name = array('a' => 'Arjun','s' => 'Sruthi','n' => 'Naveen');
print_r(array_change_key_case($name,CASE_UPPER));
//OUTPUT 
Array ( [A] => Arjun [S] => Sruthi [N] => Naveen )

Post By: Arjun
Website: arjunphp.com

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments