PHP印刷布尔值是空的,为什么呢? [英] PHP printed boolean value is empty, why?
问题描述
我是新来的PHP。我在执行一个脚本,我百思不得其解了以下内容:
I am new to PHP. I am implementing a script and I am puzzled by the following:
$local_rate_filename = $_SERVER['DOCUMENT_ROOT']."/ghjr324l.txt";
$local_rates_file_exists = file_exists($local_rate_filename);
echo $local_rates_file_exists."<br>";
这件code的显示一个空字符串,而不是0或1(或真或假)。为什么?文件似乎表明,一个布尔值始终为0或1。这是什么逻辑背后?
This piece of code displays an empty string, rather than 0 or 1 (or true or false). Why? Documentation seems to indicate that a boolean value is always 0 or 1. What is the logic behind this?
推荐答案
当你要小心来回转换与布尔,手册上说:
Be careful when you convert back and forth with boolean, the manual says:
一个布尔值TRUE将被转换为字符串1。布尔值FALSE为
转换为(空字符串)。这使得转换回来,
在布尔值和字符串之间。
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印刷布尔值是空的,为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!