PHP - Get bool to echo false when false

前端 未结 14 1666
予麋鹿
予麋鹿 2020-11-22 14:09

The following code doesn\'t print out anything:

$bool_val = (bool)false;
echo $bool_val;

But the following code prints 1:

14条回答
  •  隐瞒了意图╮
    2020-11-22 14:41

    No, since the other option is modifying the Zend engine, and one would be hard-pressed to call that a "better way".

    Edit:

    If you really wanted to, you could use an array:

    $boolarray = Array(false => 'false', true => 'true');
    echo $boolarray[false];
    

提交回复
热议问题