Home  >  Article  >  Backend Development  >  PHP中false和true问题

PHP中false和true问题

WBOY
WBOYOriginal
2016-06-06 20:23:592332browse

举个例子

<code class="php">var_dump(true == -1);//true</code>

PHP中的true和false到底对应的个啥?

回复内容:

举个例子

<code class="php">var_dump(true == -1);//true</code>

PHP中的true和false到底对应的个啥?

我感觉这个问题你可以看看手册
给了和详细的说明

在PHP中任何类型的值, 与bool比较都会被转化成bool比较

当转换为 boolean 时,以下值被认为是 FALSE:
布尔值 FALSE 本身
整型值 0(零)
浮点型值 0.0(零)
空字符串,以及字符串 "0"
不包括任何元素的数组
不包括任何成员变量的对象(仅 PHP 4.0 适用)
特殊类型 NULL(包括尚未赋值的变量)
从空标记生成的 SimpleXML 对象

如果有不对的地方还请谅解

你可以百度一下“PHP的类型转换规则”:
整型 转 布尔型 情况下
0 转换为 FALSE ,非零的其他整型数字转换为 TRUE

false == 0
true == !false == !0

http://php.net/manual/zh/language.types.boolean.php
瞅瞅

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn