在PHP中,为什么是真的投1中和假投一个空字符串? [英] In PHP why is true cast 1 and false cast an empty string?

查看:107
本文介绍了在PHP中,为什么是真的投1中和假投一个空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个布尔值TRUE将被转换为字符串1。布尔值FALSE被转换为(空字符串)。

A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string).

为什么不假投为0?

推荐答案

如果您转换为一个int,然后为一个字符串,它打印0 ..

If you cast to an int, then to a string, it prints 0's..

$x=false;
print (string)(int)$x;

0打印可以,当然,省略字符串类型转换,因为它是由打印反正做的。

Prints 0. You can, of course, omit the string type cast as it's done by print anyway.

这篇关于在PHP中,为什么是真的投1中和假投一个空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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