php - 为什么 true 在 PHP 中大于 3

标签 php types casting

我想知道为什么以下 PHP 语句返回 true?

true>=4

例如这样的行将回显 1

echo true>=4;

谁能给我解释一下这背后的逻辑?

最佳答案

4 也是true(因为它非零),true 等于true,所以它也大于或等于 true

如果将 bool 或 null 与字符串以外的任何内容进行比较,则该内容将转换为 bool。参见 the docs .

关于php - 为什么 true 在 PHP 中大于 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13711945/

相关文章:

php - 显示 php mysql 大段落的前 3 行

javascript - 如何使用ajax获取多个变量值

Haskell Curl 帮助

haskell - 确保数据的正确性

c++ - if (static_cast<bool>(x)) 与 if (x)

php - Mysql fetch - 带有 HTML 链接的结果指向表 ID

php - DOMDocument 和 HTML 实体

angularjs - Angular post json来表达

PHP:将 64 位整数转换为字符串

c++ - 类型转换 union