Is this php behaviour explained somewhere in manual? (strings with zeroes comparison)

前端 未结 5 1062
后悔当初
后悔当初 2020-12-22 01:03

Why for php

\'00\' == \'0000\'

expression is true?

Is it explained somewhere in manual?

NOTE:

相关标签:
5条回答
  • 2020-12-22 01:41

    Just read:

    If [...] the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically

    I removed the part that probably was standing in your way.

    0 讨论(0)
  • 2020-12-22 01:44

    It's also good to remember that

    If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value. enter link description here

    But everything everyone else has said is correct!

    0 讨论(0)
  • 2020-12-22 01:47

    "If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically." (PHP manual)

    0 讨论(0)
  • 2020-12-22 02:06

    Because when you compare this strings they become zeros on both sides so 0 == 0 is true, try to use '00' === '0000' here is link

    0 讨论(0)
  • 2020-12-22 02:08

    Sure

    == compares values and neglects type
    === compares values and types
    

    here is it:

    http://php.net/manual/en/language.operators.comparison.php

    *UPDATE:

    Read this part in this URL :

    http://php.net/manual/en/function.intval.php

    Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.

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