PHP中false和true问题

WBOY
Release: 2016-06-06 20:23:59
Original
2338 people have browsed it

举个例子

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

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

回复内容:

举个例子

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

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
瞅瞅

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!