Double equals and tripple equals in php

后端 未结 7 510
囚心锁ツ
囚心锁ツ 2021-01-18 01:54

I searched on StackOverflow and Google and I can\'t find the answer to this question:

Should we always use the triple equal in PHP for validation?

For exampl

7条回答
  •  春和景丽
    2021-01-18 02:33

    if you're expecting that variable that you're passing will (and must) be integer than you should use triple equal, if not than you should avoid that.

    Although, if you really want to use === than you should be doing conversion of variables to the type that you want along the way, like on this example:

    if ((int) $var === 1)
    {
    
        // will return true if the $var is 1
    }
    

提交回复
热议问题