This article mainly introduces the reference problem of PHP leaving an array after the foreach loop. It has a certain reference value. Now I share it with you. Friends in need can refer to it
eg:
result:
[1,2,3,4]
2-> [1,2,3,4]
3-> [1,2,3,3] The third time value points to the last element 3, but value is a global reference that pointed to the last element in the last cycle, so when value=3, the last element will also be The value is changed to 3
4-> [1,2,3,3] Notes: 1. The implementation principle of foreach has the concept of internal pointers 2. When the foreach loop ends, the pointer will point to the last elementHow to avoid: After using &foreach loop, unset ($a) The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website! Related recommendations:About the analysis of PHP pipeline plug-in League\Pipeline
How to use PHP to upload multiple videos at the same time Function
The above is the detailed content of How to solve php array reference problem left after foreach loop. For more information, please follow other related articles on the PHP Chinese website!