Get the App
SLTechnology News&Howtos  ›  Development  › 

How to capitalize an array by php

Shulou Source: shulou.com Published: 2022-06-02 00:51:30 10月01日 Update

I would like to share with you how php capitalizes the array. I hope you will get something after reading this article. Let's discuss it together.

Php will convert the array to uppercase methods: 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 capitalize the array elements.

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

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

We have an array like this:

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

We capitalize all the array element values in it:

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

After reading this article, I believe you have a certain understanding of "how php capitalizes arrays". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Array uppercase element function article statement association done file method more environment computer knowledge example system result industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Shulou Information Microsoft NVidia