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

查看:233
本文介绍了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>";

这件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屋!

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