DEV Community

Cover image for How To Change case of all keys in an array ?
Istiaq Nirab
Istiaq Nirab

Posted on • Edited on

How To Change case of all keys in an array ?

How to modify the case of an array’s keys In PHP, there is a specific buildin function. Function name :

array_change_key_case() 
Enter fullscreen mode Exit fullscreen mode

This function have two parameters.

Array – [the array whose keys will be changed case by case],
Case Type – [In this case there will be 2 wells. Ex: CASE_UPPER and CASE_LOWER]

However, CASE_LOWER is set the case type by default.

Example

<?php $input_array = array("name" => 'Istiaq Nirab', "Age" => "18+"); print_r(array_change_key_case($input_array, CASE_UPPER)); ?> 
Enter fullscreen mode Exit fullscreen mode

Result

Array ( [NAME] => Istiaq Nirab [AGE] => 18+ ) 
Enter fullscreen mode Exit fullscreen mode

Thanks 😊

Top comments (0)