array_change_key_case
Change the case of all keys in the array
array_change_key_case()
function converts all keys of an array into uppercase or lowercase letters.
The numeric index of the array does not change. If no optional parameter is provided (i.e. the second parameter), the default conversion is to lowercase letters.
Convert all keys of the array to capital letters:
<?php $age = array ( "Bill" => "60" , "Steve" => "56" , "Mark" => "31" ) ; print_r ( array_change_key_case ( $age , CASE_UPPER ) ) ; ?>
Try it yourself
Convert all keys of the array to lowercase letters:
<?php $age = array ( "Bill" => "60" , "Steve" => "56" , "Mark" => "31" ) ; print_r ( array_change_key_case ( $age , CASE_LOWER ) ) ; ?>
Try it yourself
If two or more keys are equal after running array_change_key_case() (such as "b" and "B"), the last element overwrites the other elements:
<?php $pets = array ( "a" => "Cat" , "B" => "Dog" , "c" => "Horse" , "b" => "Bird" ) ; print_r ( array_change_key_case ( $pets , CASE_UPPER ) ) ; ?>
Try it yourself
array_change_key_case ( array , case ) ;
parameter | describe |
---|---|
array | Required. Specifies the array to be used. |
case |
Optional. Possible values:
|