Convert all array keys to uppercase letters:
<?php$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");print_r(array_change_key_case($age,CASE_UPPER));?>The array_change_key_case() function converts all keys of an array to uppercase or lowercase letters.
array_change_key_case( array , case );
parameter | describe |
---|---|
array | Required. Specifies the array to use. |
case | Optional. Possible values: CASE_LOWER - Default value. Convert an array's keys to lowercase letters. CASE_UPPER - Convert array keys to uppercase letters. |
Return value: | Returns an array with keys with lowercase letters, or an array with keys with uppercase letters, or FALSE if array is not an array. |
---|---|
PHP version: | 4.2+ |
Convert all array keys to lowercase letters:
<?php$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");print_r(array_change_key_case($age,CASE_LOWER));?>If after running array_change_key_case() there are two or more keys with the same key (such as "b" and "B"), the last element will overwrite the other elements:
<?php$pets=array("a"=>"Cat","B"=>"Dog","c"=>"Horse","b"=>"Bird");print_r(array_change_key_case($ pets,CASE_UPPER));?>