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

How to convert an array to uppercase in php

藏色散人
藏色散人Original
2022-01-21 09:28:121634browse

php method to convert an array to uppercase: 1. Create a PHP sample file; 2. Define an associative array; 3. Use the foreach statement to traverse the array; 4. Use the strtoupper function to convert the array elements to uppercase. .

How to convert an array to uppercase in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

php How to convert an array to uppercase?

How to change the key value to uppercase in PHP associative array

We have such an array:

$fruits = array('A' => 'Apple', 'B' => 'Banana', 'c' => 'Cherry', 'o' => 'Orange');

We convert all the array element values ​​​​in it to uppercase:

 $value){
    $fruits[$key]=strtoupper($value);
}
echo "转换为大写后:";
var_dump($fruits);
?>

Use the foreach statement to traverse the $fruits array, and use the strtoupper($value) function in the loop to convert the array element $value to uppercase, so the output result is:

How to convert an array to uppercase in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert an array to uppercase in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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