我有点困惑php函数如何boolval
作品。考虑以下因素
<?php echo boolval(true); // prints 1
与对比
<?php echo boolval(false); // prints nothing?
为什么我没有返回真/假?为什么是 boolval(false)
什么都不返回?
我在尝试解析 $argv
时遇到了这个问题对于 bool 参数。从 $argv
中提取 bool 值的正确做法是什么?如果没有这个功能?
最佳答案
A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.
使用
echo $boolres ? 'true' : 'false';
关于php - 为什么 boolval(false) 在 php 中返回空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38101560/