Home Backend Development PHP Tutorial In php, 0 == false, 0 == false will be equal, and false != false is the reason.

In php, 0 == false, 0 == false will be equal, and false != false is the reason.

Jul 28, 2016 am 08:27 AM
dump false param true

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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is a dump file? What is a dump file? Jan 12, 2024 pm 04:58 PM

A dump file usually refers to a binary file, also known as a dump file or core dump file. This kind of file is generated by the computer system when it encounters a serious error or abnormal situation. It is used to store the status, stack, registers, memory images, logs and other information of the system or application.

What is the meaning of dump in computer What is the meaning of dump in computer Jun 10, 2021 am 11:25 AM

In computers, dump means "dump" in Chinese, which generally refers to exporting and dumping data into files or static forms, that is, saving dynamic (volatile) data into static data (persistent data). There is no need to dump data like programs that are originally stored in storage media (such as hard disks).

Detailed explanation of the meaning of true in PHP functions Detailed explanation of the meaning of true in PHP functions Mar 16, 2024 am 08:57 AM

Detailed explanation of the meaning of true in PHP function In PHP, true is a Boolean value, representing the state of "true" or "yes". Using true in a function is usually used to express that a condition is true or to return a success status. This article will explain in detail the meaning of true in PHP functions from different perspectives, and give specific code examples. 1. Conditional judgment when true is returned: In PHP functions, true is usually used in conditional judgment to indicate that the condition is true. For example: functioni

What does true mean in PHP function? What does true mean in PHP function? Mar 16, 2024 pm 12:12 PM

Title: What does true mean in PHP functions? In PHP programming, true represents true in a Boolean value, usually indicating the state of "true". When true is used in a function, it is usually used to determine whether a condition is true or to perform some operation. The following will use specific code examples to illustrate what true means in PHP functions. example:

The difference and usage of equals() and == in Java The difference and usage of equals() and == in Java Mar 07, 2024 pm 03:28 PM

In Java development, there is a seemingly simple, but there are a lot of topics and questions on the Internet, that is, what is the difference between equals() and the == operator ==: The operator is used to compare whether the addresses of two objects are equal equals( ): method is used to compare whether the contents of two objects are equal. Today's content introduction, which takes about 9 minutes. To better understand this difference, let us look at an example: Stringstr1=newString("Hello");Stringstr2=newString(" Hello");System.out.println(str1.equals(str2));//output trueSystem

SpringBoot interceptor returns false to show how to solve cross-domain problems SpringBoot interceptor returns false to show how to solve cross-domain problems May 13, 2023 pm 05:10 PM

The project recently added an IP black and white list function. I found that if the IP filtering interceptor returns false, the front end will display cross-domain. After trying to modify the MVC configuration class, I found that it still didn't work. Finally, I added a judgment to the interceptor @OverridepublicbooleanpreHandle. (HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler)throwsIOException{//-----------Just add this-----------if(!(handlerinstanceo

what is linux param what is linux param Mar 10, 2023 am 08:58 AM

Linux param refers to the "module_param" function, which is used to pass command line parameters; when programming in user mode, command line parameters can be passed through the parameters of "main()", and when writing a kernel module, pass "module_param()" to pass parameters.

How to install redis-dump tool How to install redis-dump tool May 27, 2023 pm 05:52 PM

The redis-dump tool is used to build the environment for data migration in the cluster: 192.168.19.201redis-cluster637970017002rvmredis-dump192.168.19.202redis-cluster637970017002192.168.19.203redis-cluster637970017002 due to the installation of the redis-dump tool You need to use rvm and gem tools, so they must be installed in advance. 1. Install the dependency packages required to install rvm and other tools in advance #yum-yinstallzlibzlib-develpcrepcre

See all articles