Ang function na array_change_key_case() ng PHP

Mga Halimbawa

Ibabago ang lahat ng key ng array sa pang-apat na titik:

<?php
$age=array("Bill"=>"60","Steve"=>"56","Mark"=>"31");
print_r(array_change_key_case($age, CASE_UPPER));
?>

Run Instance

Pagsasaayos at Paggamit

Ang function na array_change_key_case() ay nagbabago ng lahat ng key ng array sa pang-apat na titik o pang-ibig sabihin na may tatlong titik.

The numeric indices of the array do not change. If the optional parameter is not provided (i.e., the second parameter), it is converted to lowercase by default.

Tips and Comments

Note:If two or more keys are the same when running the function, the last element will overwrite other elements (see Example 2).

Syntax

array_change_key_case(array,case);
Parameter Description
array Required. Specifies the array to be used.
case

Optional. Possible values:

  • CASE_LOWER - Default value. Converts the keys of the array to lowercase letters.
  • CASE_UPPER - Converts the keys of the array to uppercase letters.

Technical Details

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

More Examples

Example 1

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));
?>

Run Instance

Example 2

If there are two or more keys that are equal after running array_change_key_case() (such as "b" and "B"), the last element will overwrite other elements:

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

Run Instance