Latest web development tutorials

PHP array_change_key_case () function

PHP Array Reference Complete PHP Array Reference

Examples

All key array converted to uppercase letters:

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

Running instance »

Definition and Usage

array_change_key_case () all of the key functions of the array are converted to uppercase or lowercase letters.


grammar

array_change_key_case( array , case );

参数 描述
array 必需。规定要使用的数组。
case 可选。可能的值:
  • CASE_LOWER - 默认值。将数组的键转换为小写字母。
  • CASE_UPPER - 将数组的键转换为大写字母。

technical details

return value: Returns an array of keys with lowercase letters, or return an array of keys with a capital letter, or if the array is not an array returns FALSE.
PHP version: 4.2+


More examples

Example 1

All key array converted to lowercase:

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

Running instance »

Example 2

If you run End array_change_key_case () after two or more of the same key (for example, "b" and "B"), the last element will cover other elements:

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

Running instance »


PHP Array Reference Complete PHP Array Reference