有没有办法配置 PHP 以便回显 0==1;输出 0 或假


Is there a way to configure PHP so that echo 0==1; outputs 0 or false?

有没有办法通过.ini文件配置 PHP,以便echo 0==1;输出0false

使用三元运算符(PHP 三元运算符):

echo (0==1) ? 'false' : 'true';

您可以将表达式类型转换为整数:

echo (int)(1==0);

这里有一个名为Converting to boolean的部分,但仍然没有完全解释:http://www.php.net/manual/en/language.types.boolean.php

它实际上是自动false转换为空字符串("")(根据设计,请参阅上面的链接),然后echo这样输出它,因为echo只接受字符串:

echo (int)false;    // 0
echo (int)true;     // 1
echo (string)false; // nothing
echo (string)true;  // 1