// case 1:
echo false . 'test'; // output: test
// case 2:
echo true . 'test'; // output: 1test
Run Code Online (Sandbox Code Playgroud)
为何true输出1但false没有?
简单:
可以使用强制转换
(string)或strval()函数将值转换为字符串.字符串转换在需要字符串的表达式范围内自动完成.使用echo()或print()函数时,或者将变量与字符串进行比较时会发生这种情况.布尔值TRUE值将转换为字符串
"1".Boolean FALSE转换为""(空字符串).这允许在布尔值和字符串值之间来回转换.
http://php.net/manual/en/language.types.string.php#language.types.string.casting
| 归档时间: |
|
| 查看次数: |
278 次 |
| 最近记录: |