Underlying philosophy behind php type comparisons

前端 未结 7 1819
不思量自难忘°
不思量自难忘° 2021-02-10 00:38

So there\'s this page on the php site which shows the result of comparing different values:

http://php.net/manual/en/types.comparisons.php

This is a helpful refe

相关标签:
7条回答
  • 2021-02-10 01:10

    I look at it the following way:

    1. PHP is designed as a web programming language and all the input of the pages is based on strings [human-like perception] [This is by the way is also true for JavaScript]
    2. Hence, all the strings which look like numbers (is_numeric() function), preliminary behave like numbers [comparison, casting].
    3. That explains why extreme cases, like "0" are first implicitly thought to be cast to (int)0 and only then to false.
    0 讨论(0)
提交回复
热议问题