Arrays
PHP Manual

array_change_key_case

(PHP 4 >= 4.2.0, PHP 5)

array_change_key_case — Changes all keys in an array

說明

array array_change_key_case ( array $input [, int $case ] )

Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.

參數

input

The array to work on

case

Either CASE_UPPER or CASE_LOWER (default)

Return值

Returns an array with its keys lower or uppercased, or false if input is not an array.

錯誤/例外

Throws E_WARNING if input is not an array.

範例

Example#1 array_change_key_case() example

<?php
$input_array 
= array("FirSt" => 1"SecOnd" => 4);
print_r(array_change_key_case($input_arrayCASE_UPPER));
?>

上例將輸出:

Array
(
    [FIRST] => 1
    [SECOND] => 4
)

註釋

Note: If an array has indices that will be the same once run through this function (e.g. "keY" and "kEY"), the value that is later in the array will override other indices.


Arrays
PHP Manual