Convert all keys in an array to uppercase:
<?php $age=array(“Peter”=>“35”,“Ben”=>“37”,“Joe”=>“43”); print_r(array_change_key_case($age,CASE_UPPER)); ?> |
The array_change_key_case() function modifies all keys in an array to either lowercase or uppercase.
array_change_key_case(array, case) |
Parameter |
Description |
array |
Required. Specifies the array to use |
case |
Optional. Possible values:
|
Return Value: |
Returns an array with its keys converted to lowercase or uppercase, or |
PHP Version: |
4.2+ |
Convert all keys in an array to lowercase:
<?php $age=array(“Peter”=>“35”,“Ben”=>“37”,“Joe”=>“43”); print_r(array_change_key_case($age,CASE_LOWER)); ?> |
If two or more keys result in the same value after using array_change_key_case()
(e.g., “b” and “B”), the most recent key-value pair will override the others.
<?php $pets=array(“a”=>“Cat”,“B”=>“Dog”,“c”=>“Horse”,“b”=>“Bird”); print_r(array_change_key_case($pets,CASE_UPPER)); ?> |