Underlying philosophy behind php type comparisons

前端 未结 7 1821
不思量自难忘°
不思量自难忘° 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.

提交回复
热议问题