PHP中的true/false如何工作? [英] How does true/false work in PHP?
本文介绍了PHP中的true/false如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道PHP如何在内部处理 true/false 比较.
我了解将true定义为1,将false定义为0.
当我执行if("a"){ echo "true";}
时,它会回显" true ". PHP如何将"a"识别为1?
I wonder how PHP handles true/false comparison internally.
I understand that true is defined as 1 and false is defined as 0.
When I do if("a"){ echo "true";}
it echos "true". How does PHP recognize "a" as 1 ?
推荐答案
转换为布尔值时,以下值为FALSE:
When converting to boolean, the following values are considered FALSE:
- 布尔值
FALSE
本身 - 整数
0
(零) - 浮点数
0.0
(零) - 空字符串和字符串
'0'
- 具有零个元素的数组
- 具有零成员变量的对象(仅PHP 4)
- 特殊类型
NULL
(包括未设置的变量) - 从空标签创建的SimpleXML对象
- the boolean
FALSE
itself - the integer
0
(zero) - the float
0.0
(zero) - the empty string, and the string
'0'
- an array with zero elements
- an object with zero member variables (PHP 4 only)
- the special type
NULL
(including unset variables) - SimpleXML objects created from empty tags
所有其他值都被视为TRUE .
这篇关于PHP中的true/false如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文