Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

array
php
communitycreator

What is the array_change_key_case method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The array_change_key_case method can change the case of all keys of the array to either upper or lower case keys. The numeric keys are left unchanged.

Syntax

array_change_key_case(array $array, int $case = CASE_LOWER): array

Arguments

  • array: The array in which the case of the keys is to be changed.

  • case: Denotes the resulting case of array keys. The possible values can be:

    • CASE_UPPER: Equivalent int value is 1.
    • CASE_LOWER: Equivalent int value is 0.

case is an optional value. The default value is CASE_LOWER.

Example

<?php
$arr = array(10, 20, "onE" => 1, "TwO" => 2, "THrEe" => 3);
echo "Converting to Uppercase\n";
print_r(array_change_key_case($arr, CASE_UPPER));
echo "Converting to Lowercase\n";
print_r(array_change_key_case($arr, CASE_LOWER));
?>

In the code above, we created an array and converted all the array’s keys to uppercase, and then tried to convert to lowercase using the array_change_key_case method.

RELATED TAGS

array
php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring