Home > Article > Backend Development > How to set the php array key name
How to set the php array key name: 1. Create a PHP sample file; 2. Define an array; 3. Use foreach to traverse the array elements; 4. Modify the array key name in foreach and reassign the value. .
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
php How to set the array key name? Add characters to the array key name
Create a new PHP file named test.php to explain how PHP adds characters to the array key name.
In the test.php file, use the header() method to set the encoding format of the page to utf-8.
In the test.php file, define an array for testing.
In the test.php file, use foreach to traverse the array elements. Within foreach, add an underline to the array key name and reassign the value. At the same time, use the unset function to delete the original The array element value corresponding to the key name.
In the test.php file, use print_r to output the processed array.
Open the test.php file in the browser to view the results.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to set the php array key name. For more information, please follow other related articles on the PHP Chinese website!