有没有办法让"真" /"假"从PHP布尔字符串值? [英] Is there a way to get "true"/"false" string values from a Boolean in PHP?

查看:132
本文介绍了有没有办法让"真" /"假"从PHP布尔字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我转换为布尔(使用(布尔)),是否有一个内置的方式来获得PHP实际返回的常量真实。目前,我得到 1 或空白,分别评估为true和false。

When I cast to Boolean (using (bool)), is there a built in way to get PHP to actually return the constants true or false. At the moment I'm getting 1 or blank, which evaluate to true and false respectively.

我想更明确的语义返回的值。但是,如果我不能得到它,我就解决与1和空白。

I want the value returned for clearer semantics. However, if I can't get it, I'll just settle with 1 and blank.

推荐答案

PHP显示布尔值1(真)或空字符串(假)输出时。

PHP displays boolean values as 1 (true) or empty string (false) when outputted.

如果您要检查它是否真正使用 == (如果隐式转换OK)或 === (如果它不是)。例如:

If you want to check if it's true or false use == (if implicit conversion is OK) or === (if it's not). For example:

echo $val ? 'true' : 'false'; // implicit conversion
echo $val === true ? 'true' : 'false'; // no conversion

我不知道有什么办法让PHP输出布尔值本身为真正

这篇关于有没有办法让"真" /"假"从PHP布尔字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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