PHP array_change_key_case() function

Description

The array_change_key_case() function changes all keys in an array to lowercase or uppercase.

Syntax

PHP array_change_key_case() function has the following syntax.

array_change_key_case(array,case);

Parameter

ParameterIs RequiredDescription
arrayRequired.Specifies the array to use
caseOptional.Case to use

Possible values for case:

ValueMeaning
CASE_LOWERDefault value. Changes the keys to lowercase
CASE_UPPERChanges the keys to uppercase

Return

array_change_key_case() function returns an array with its keys in lowercase or uppercase, or FALSE if array is not an array.

Example

Change the lowercase key to uppercase.


<?php
    $age=array("a"=>"a","b"=>"b","c"=>"c");
    print_r(array_change_key_case($age,CASE_UPPER));
?>

The code above generates the following result.

Example 2

If two or more keys will be equal after running array_change_key_case() (e.g. "b" and "B"), the latest array will override the other.


<?php
    $pets=array("a"=>"a","b"=>"b","B"=>"B","A"=>"A");
    print_r(array_change_key_case($pets,CASE_UPPER));
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions