Open In App

PHP | array_change_key_case() Function

The array_change_key_case() function is an inbuilt function in PHP and is used to change case of all of the keys in a given array either to lower case or upper case.

Syntax:



array array_change_key_case(in_array, convert_case)

Parameters: This function accepts two parameters out of which one is mandatory and the other is optional. The two parameters are described below:

  1. in_array (mandatory): This parameter refers to the array whose key’s case is needed to be changed.
  2. convert_case (optional): This is an optional parameter and refers to the ‘case’ in which we need to convert the keys of the array. This can take two values, either CASE_UPPER or CASE_LOWER. CASE_UPPER value determines the uppercase and CASE_LOWER determines lowercase. If the convert_case parameter is not passed then it’s default value is taken which is CASE_LOWER.

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



Return Type: The function returns an array with the changed case of the key, either to lowercase or to upper case.

Let us now look at some programs to get a better understanding of working of array_change_key_case() function.


Article Tags :