Double equals and tripple equals in php

后端 未结 7 465
囚心锁ツ
囚心锁ツ 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:32

    It depends on what you want to do.
    Given that from forms, data comes as strings, == is handy because it can compare, for example, strings that represent numbers with numbers with no additional type casting.

    if ($_GET['amount'] == 10) {
        //...
    }
    

    So no, it's not better to always use ===.

提交回复
热议问题