Home > Backend Development > PHP Problem > How to convert array key to uppercase in php

How to convert array key to uppercase in php

青灯夜游
Release: 2023-03-11 15:32:02
Original
3487 people have browsed it

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 );".

How to convert array key to uppercase in php

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);
Copy after login

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.

ParametersDescription
arrayRequired. Specifies the array to use.
caseOptional. Possible values:
  • CASE_LOWER - Default value. Convert an array's keys to lowercase letters.
  • CASE_UPPER - Convert array keys to uppercase letters.

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));
?>
Copy after login

Output:

Array
(
    [FIRST] => 1
    [SECOND] => 4
)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template