array_change_key_case
Change the case of all keys in the array
PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8
The array_change_key_case() function is used to convert all key names in an array to lowercase or uppercase.
<span class="fun">array array_change_key_case(array $array, int $case = CASE_LOWER)</span>
Returns a new array whose key name has changed case, the original array is not modified.
$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>
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.