Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_change_key_case() Function

PHP array_change_key_case() Function

PHP Array Reference ManualComplete PHP Array Reference Manual

Example

Convert all keys of an array to uppercase:

" 35 " , " Ben " => " 37 " , " Joe " => " 43 " ) ; print_r ( array_change_key_case ( $age , CASE_UPPER ) ) ; ?>

Run Example »


Definition and Usage

The array_change_key_case() function converts all keys of an array to uppercase or lowercase.


Syntax

array_change_key_case(

array

,

case

);

Parameters Description
array Required. Specifies the array to use.
case Optional. Possible values:
  • CASE_LOWER - Default. Converts the array keys to lowercase.
  • CASE_UPPER - Converts the array keys to uppercase.
  • |

    Technical Details

    Return Value: Returns an array with lowercase keys, or an array with uppercase keys, or if array it is not an array, returns FALSE.
    PHP Version: 4.2+

    More examples

    Example 1

    Convert all keys of an array to lowercase:

    "35","Ben"=>"37","Joe"=>"43"); print_r(array_change_key_case($age,CASE_LOWER)); ?>

    Run Example »

    Example 2

    If two or more keys are identical after array_change_key_case() runs (such as "b" and "B"), the last element will overwrite the others:

    "Cat","B"=>"Dog","c"=>"Horse","b"=>"Bird"); print_r(array_change_key_case($pets,CASE_UPPER)); ?>

    Run Example »


    PHP Array Reference ManualComplete PHP Array Reference Manual