我是 PHP 新手。我正在执行一个脚本,我对以下内容感到困惑:
$local_rate_filename = $_SERVER['DOCUMENT_ROOT']."/ghjr324l.txt";
$local_rates_file_exists = file_exists($local_rate_filename);
echo $local_rates_file_exists."<br>";
这段代码显示一个空字符串,而不是 0 或 1(或 true 或 false)。为什么?文档似乎表明 boolean 值始终为 0 或 1。这背后的逻辑是什么?
最佳答案
使用 boolean 值来回转换时要小心,the manual says :
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 (int)$local_rates_file_exists."<br>";
关于PHP 打印 boolean 值是空的,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9042002/