Current Location: Home> Function Categories> array_change_key_case

array_change_key_case

Change the case of all keys in the array
Name:array_change_key_case
Category:Array
Programming Language:php
One-line Description:Change all keys in the array to lowercase or uppercase.

array_change_key_case

Applicable to PHP version

PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8

Function description

The array_change_key_case() function is used to convert all key names in an array to lowercase or uppercase.

Function Syntax

 <span class="fun">array array_change_key_case(array $array, int $case = CASE_LOWER)</span>

parameter

  • $array : Must. The input array.
  • $case : optional. It can be CASE_LOWER (default, convert key names to lower case) or CASE_UPPER (convert key names to upper case).

Return value

Returns a new array whose key name has changed case, the original array is not modified.

Example

 $input_array = array( "FirSt" => 1, "SecOnd" => 4 ); $result = array_change_key_case($input_array, CASE_LOWER);<br>
print_r($result);</p>
<p>$result_upper = array_change_key_case($input_array, CASE_UPPER);<br>
print_r($result_upper);<br>

Description of sample code or other description of function

In the example above, $input_array is an array with mixed case key names. All key names can be converted to lowercase or uppercase via the array_change_key_case() function. This function is often used to uniformly process array key names, especially in scenarios where array comparisons or standardized outputs are required.

Note: If the converted key names are repeated, the subsequent values will overwrite the previous one.

Similar Functions
Popular Articles