PHP打印的布尔值是空的,为什么? [英] PHP printed boolean value is empty, why?

查看:69
本文介绍了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打印的布尔值是空的,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆