How to convert an array to uppercase in php

藏色散人
Release: 2023-03-14 21:56:01
Original
1603 people have browsed it

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

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

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

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!

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