array_change_key_case – Convert Array Keys to Uppercase or Lowercase in PHP

array_change_key_case() is a PHP function that transforms all string keys in an input array to either lower‑case or upper‑case based on the specified case constant, leaving numeric indexes unchanged, and returns the modified array or FALSE if the input is not an array.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
array_change_key_case – Convert Array Keys to Uppercase or Lowercase in PHP

array_change_key_case() returns an array with all string keys converted to either lower‑case or upper‑case.

Explanation: The function changes the case of keys in the $input array according to the $case parameter (either CASE_LOWER or CASE_UPPER). Numeric indexes are not affected.

Parameters

input – The array to be processed.

case – Optional. One of the constants CASE_UPPER or CASE_LOWER. Default is CASE_LOWER.

Return value

Returns the array with keys converted to the chosen case; if $input is not an array, the function returns FALSE.

Example

<?php
$input_array = array(
    "FirSt" => 1,
    "SecOnd" => 4
);
print_r(array_change_key_case($input_array, CASE_UPPER));
?>

Output:

Array
(
    [FIRST] => 1
    [SECOND] => 4
)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendprogrammingArrayfunctionkey case
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.