Forgetting double equal-sign in php if-statement

前端 未结 1 1376
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 23:27

While coding, i sometimes make the error of writing a single = instead of == in an if-statement. So lets say i have this:



        
1条回答
  •  长情又很酷
    2021-01-24 23:50

    Just change the order to this:

    if('jan' == $name) {
    

    This is known under Yoda conditions:

    enter image description here

    So if you now make the mistake:

    if('jan' = $name) {
    

    This will give you an error!

    0 讨论(0)
提交回复
热议问题