Hello friends,
If you want to change the array keys in either upper case or lower case then you can use a predefined array function of PHP which is "array_change_key_case()". array_change_key_case returns an array with all keys from array lower or upper cased. Numbered indices are left as is.
Parameters:
array: The array to work on
case: Either CASE_UPPER or CASE_LOWER (default)
Here is some example which will explain you clearly-
<?php
$inputArray = array("First" => 1, "Second" => 2);
print_r(array_change_key_case($inputArray, CASE_UPPER));
?>
Output:
Array
(
[FIRST] => 1
[SECOND] => 2
)
Here in another lower case example-
<?php
$inputArray = array("First" => 1, "Second" => 2);
print_r(array_change_key_case($inputArray, CASE_LOWER));
?>
Output:
Array
(
[first] => 1
[second] => 2
)
0 Comment(s)