PHP printed boolean value is empty, why?(PHP打印的布尔值是空的,为什么?)
问题描述
我是 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>";
这段代码显示一个空字符串,而不是 0 或 1(或 true 或 false).为什么?文档似乎表明布尔值始终为 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打印的布尔值是空的,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP打印的布尔值是空的,为什么?


- 从 PHP 中的输入表单获取日期 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01