Home  >  Article  >  Backend Development  >  How to loop through an array in php and modify the values

How to loop through an array in php and modify the values

藏色散人
藏色散人Original
2020-10-12 09:19:032940browse

How to loop through an array and modify the value in php: 1. Directly modify the value of the array key through a foreach loop; 2. Add an "&" symbol in front of "$item" to modify the value of the array key.

How to loop through an array in php and modify the values

Recommended: "PHP Video Tutorial"

Such modifications are not It's not the modification itself. $item is equivalent to assigning a value in the array, just like the value type in JAVA. I just took your value, not your memory address. That's all $ Changing the item will not affect the array

The first way is to directly modify the value of the array key

This is OK Modified

The second method is to add an ampersand in front of $item, so that it can be modified directly like an object

The above is the detailed content of How to loop through an array in php and modify the values. 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