search
HomeBackend DevelopmentPHP TutorialIn php, 0 == false, 0 == false will be equal, and false != false is the reason.

First look at a special case:

var_dump(0 == 'false'), returns bool(true), PHP determines that 0 is equal to any string;

var_dump(0==='false'), returns bool( false), the types and values ​​must be equal if they are congruent.
var_dump(0 == false), returns bool(true),


The reasons for the above results (translated from php official documentation):

1. For bool type:

When you output the bool type or When used in a statement, it will be converted into a number , true becomes 1, and false becomes 0.

For example, $a = true; var_dump($a+1), returns (int)2; $a is converted to 1, and the sum is 2;

A bool variable expresses a true value, and Rather than expressing a 0 or 1; Boolean types are not iconic constants, they have values.

2. String type:

php will always automatically try to convert strings into numbers. For example, var_dump('abc'+3'), returns int(3),

First 'abc' is converted into the number 0, and the addition becomes 3;


Method to detect the type of variable:
1. var_dump ($param) , will return the type and value of the variable.

2. Use is_int(), is_bool(), is_string(); functions to return true and false,


commonly used type conversion methods.
Variable $param

Integer type (int)$param

Character type (string)$param

Boolean type (bool)$param

Another way to convert to Boolean type: $a = !5, $a is false ,$a = !!5,$a is true;


The above introduces the reasons why 0 == false, 0 == false will be equal, and false ! = false in php. , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.

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
dump文件是什么文件dump文件是什么文件Jan 12, 2024 pm 04:58 PM

dump文件通常是指一种二进制文件,也被称为转储文件或核心转储文件。这种文件是计算机系统在遇到严重错误或异常情况时生成的,用于存储系统或应用程序的状态、堆栈、寄存器、内存映像、日志等信息。

dump在计算机中的意义是什么dump在计算机中的意义是什么Jun 10, 2021 am 11:25 AM

在计算机中,dump的中文意思为“转储”,一般指将数据导出、转存成文件或静态形式,即将动态(易失)的数据,保存为静态的数据(持久数据)。像程序这种本来就保存在存储介质(如硬盘)中的数据,是没有必要dump。

PHP函数中true的含义详解PHP函数中true的含义详解Mar 16, 2024 am 08:57 AM

PHP函数中true的含义详解在PHP中,true是一个布尔值,代表"真"或者"是"的状态。在函数中使用true通常用于表达一个条件成立或者返回一个成功的状态。本文将从不同的角度详细解释在PHP函数中true的含义,以及给出具体的代码示例说明。一、返回true的情况条件判断:在PHP函数中,true通常用于条件判断中,表示条件成立。例如:functioni

PHP函数中true代表什么意思?PHP函数中true代表什么意思?Mar 16, 2024 pm 12:12 PM

标题:PHP函数中true代表什么意思?在PHP编程中,true代表布尔值中的真,通常表示“真”的状态。在函数中使用true时,通常用于判断条件是否为真或执行某些操作。下面将通过具体的代码示例来说明在PHP函数中true代表什么意思。例子:

Java中的equals()与==的区别与用法Java中的equals()与==的区别与用法Mar 07, 2024 pm 03:28 PM

在Java开发中有有一个看似简单,但是在网上有大量关于话题和问题,就是equals()和==操作符有什么区别==:操作符用于比较两个对象的地址是否相等equals():方法用于比较两个对象的内容是否相等今日内容介绍,大约花费9分钟图片为了更好地理解这个区别,让我们看一个例子:Stringstr1=newString("Hello");Stringstr2=newString("Hello");System.out.println(str1.equals(str2));//输出trueSystem

SpringBoot拦截器返回false显示跨域问题怎么解决SpringBoot拦截器返回false显示跨域问题怎么解决May 13, 2023 pm 05:10 PM

项目最近添加了一个ip黑白名单的功能,发现如果ip过滤的拦截器返回false后前端会显示跨域,尝试修改MVC配置类后发现还是不行,最后在拦截器加了个判断就可以了@OverridepublicbooleanpreHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler)throwsIOException{//-----------加上这个就好了-----------if(!(handlerinstanceo

linux param是什么linux param是什么Mar 10, 2023 am 08:58 AM

linux param指的是“module_param”函数,其作用是传递命令行参数;在用户态下编程可以通过“main()”的参数来传递命令行参数,而编写一个内核模块则通过“module_param()”来传递参数。

如何安装redis-dump工具如何安装redis-dump工具May 27, 2023 pm 05:52 PM

redis-dump工具用于集群中的数据迁移搭建环境:192.168.19.201redis-cluster637970017002rvmredis-dump192.168.19.202redis-cluster637970017002192.168.19.203redis-cluster637970017002由于安装redis-dump工具需要使用rvm和gem工具所以要提前安装1.提前安装好安装rvm等工具所需要的依赖包#yum-yinstallzlibzlib-develpcrepcre

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools