In PHP, you can use the array_change_key_case() function to convert the array key to uppercase. This function can convert all the key names of the array to uppercase letters or lowercase letters. The syntax "array_change_key_case(array,CASE_UPPER );".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use array_change_key_case () function to convert the array key to uppercase.
Syntax format:
array_change_key_case(array,case);
array_change_key_case() function will change all key names in the array array to all lowercase or uppercase according to case. The default is to lowercase. This function does not change the numeric index.
Parameters | Description |
---|---|
array | Required. Specifies the array to use. |
case | Optional. Possible values:
|
Return value: Returns an array whose keys are all lowercase or all uppercase; if the input value (array) is not an array, then return false
Description: If the input value (array) is not an array, an error warning (E_WARNING) will be thrown.
Example: Convert array key to uppercase
<?php $input_array = array("FirSt" => 1, "SecOnd" => 4); print_r(array_change_key_case($input_array, CASE_UPPER)); ?>
Output:
Array ( [FIRST] => 1 [SECOND] => 4 )
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to convert array key to uppercase in php. For more information, please follow other related articles on the PHP Chinese website!