Discuz! Board

 找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 6|回復: 0

common mistakes in writing php codes

[複製鏈接]

1

主題

1

帖子

5

積分

新手上路

Rank: 1

積分
5
發表於 2024-4-30 13:14:40 | 顯示全部樓層 |閱讀模式
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.


回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|自動贊助|z

GMT+8, 2025-5-23 06:53 , Processed in 0.033136 second(s), 19 queries .

抗攻擊 by GameHost X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回復 返回頂部 返回列表
一粒米 | 中興米 | 論壇美工 | 設計 抗ddos | 天堂私服 | ddos | ddos | 防ddos | 防禦ddos | 防ddos主機 | 天堂美工 | 設計 防ddos主機 | 抗ddos主機 | 抗ddos | 抗ddos主機 | 抗攻擊論壇 | 天堂自動贊助 | 免費論壇 | 天堂私服 | 天堂123 | 台南清潔 | 天堂 | 天堂私服 | 免費論壇申請 | 抗ddos | 虛擬主機 | 實體主機 | vps | 網域註冊 | 抗攻擊遊戲主機 | ddos |