Home > Article > Backend Development > How to convert an array to uppercase in php
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. .
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:
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!