PHP array_change_key_case()Functions

PHP Array 参考手册Complete PHP Array Reference

Examples

Convert all keys of an array to uppercase:

<?php $age=array("Peter"=>"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 letters.


Syntax

array_change_key_case(array,case);

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

Technical Details

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


More Examples

Example 1

Convert all keys of an array to lowercase:

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

Run Example »

Example 2

If, after running array_change_key_case(), two or more keys are the same (e.g. "b" and "B"), the last element will override the other elements:

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

Run Example »


PHP Array 参考手册Complete PHP Array Reference Other Extensions