|
PHP is a popular scripting language used by about 79% of the world's websites. This language is eight times more popular than its closest competitor, ASP.NET. How to write profitable php codes, it is easy to learn and has high execution speed and is compatible with most platforms, databases and browsers. The popularity of PHP has created a large community of developers for it. The high number of specialists has led to high competition and lower salary requests, which will be useful for reducing development costs. The popularity of PHP is a logical result of its many advantages. These advantages make PHP a powerful and effective development tool, but despite its simplicity, it has become a complex language with many details.
These details can confuse programmers and lead to hours of debugging. This article discusses Uruguay Phone Number List the ten most common mistakes that programmers should avoid when writing PHP code. foreach ($arr as &$value)In this code, the & symbol is used, which makes the value$ variable point to each element of the arr$ array as a reference. Therefore, any changes you make to value$ will also be reflected in the arr$ array. Subsequent operations on value$ may inadvertently change the last element of the arr$ array. For example, if the mentioned code continues as follow foreach ($arr as &$value)he presence of & in the first loop causes the last element of the arr$ array to change and give its value to value$.

For this reason, in the last iteration of the loop, the number 6 is printed twice. The result of execution can be seen in picture (1). Common errors in writing php codes picture (1) By executing the second foreach function, it is determined that the last value in the arr$ array is equal to 6, but why does such a problem occur? After passing through the first foreach loop, the arr$ array remains unchanged but, as explained above, value$ is set as a reference pointing to the last element in the arr$ array. Because foreach copies each element of the array arr$ into value$ at each step of the loop. Considering the addressing of array elements arr$ it will be checked that during each step What happens from the second foreach loop.
|
|