Home > Article > Backend Development > How to loop through an array in php and modify the values
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.
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!