English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
array_change_key_case()A função altera o tamanho das letras das chaves do array transmitido e retorna um array com todas as chaves em minúsculas ou maiúsculas, conforme a opção transmitida...
By default, this function returns keys in lowercase letters.
array array_change_key_case(array $input[, int $case])
Serial number | Parameters and descriptions |
---|---|
1 | $input (required) This is the array you want to change the case of all keys. |
2 | $case (optional) This will take the constant valueCASE_UPPERorCASE_LOWER. If you do not pass this value, the function will change the keys to lowercase. |
The PHP array_change_key_case() function returns an array whose keys are in lowercase or uppercase format; if the input passed is not a valid PHP array, it returnsFALSE.
This function was originally introduced in PHP version4.2introduced in version .0.
Try the following example, where we will convert all keys to uppercase-
<?php $input = array("FirSt"=> 10, "SecOnd" => 400, "Third" => 800, ); print_r(array_change_key_case($input, CASE_UPPER)); ?>test to see‹/›
Output result
Array ( [FIRST] => 10 [SECOND] => 400 [THIRD] => 800 )
The following example will convert all keys to lowercase-
<?php $input = array("FirSt"=> 10, "SecOnd" => 400, "Third" => 800, ); print_r(array_change_key_case($input, CASE_LOWER)); ?>test to see‹/›
Output result
Array ( [first] => 10 [second] => 400 [third] => 800 )
Let's check how it will work by default if we do not pass the second option in the function-
<?php $input = array("FirSt"=> 10, "SecOnd" => 400, "Third" => 800, ); print_r(array_change_key_case($input)); ?>test to see‹/›
Output result
Array ( [first] => 10 [second] => 400 [third] => 800 )
The following example returns FALSE and issues a warning because we are trying to pass a simple PHP string instead of a PHP array-
<?php $input = "This is a string"; print_r(array_change_key_case($input, CASE_LOWER)); ?>test to see‹/›
This will not produce any output, but will display the following warning. If you want to check the return value of the function, it will be FALSE-
PHP Warning: array_change_key_case() expects parameter 1 to be array, string given in main.php on line 3