The difference between 0, ' ', null and false in php
Many people in PHP still don’t understand the difference between 0, "", null and false in PHP. These differences sometimes affect the correctness and security of data judgment, causing a lot of trouble for the test run of the program.
Let’s look at an example first:
$str1 = null;
$str2 = false;
echo $str1==$str2 ? 'Equal' : 'Not equal';
$str3 = " ";
$str4 = 0;
echo $str3==$str4 ? 'Equal' : 'Not equal';
$str5 = 0;
$str6 = '0';
echo $str5= ==$str6 ? 'Equal' : 'Not equal';
$str7=0;
$str=false;
echo $str7==$str8 ? 'Equal' : 'Not equal';
? >
Run result:
//Equal, equal, not equal, equal.
The reason is that variables in PHP are stored in C language structures. Empty strings, NULL, and false are all stored with a value of 0. This structure has a member variable like zend_uchartype;. It is used to save the type of variables, and the type of empty string is string, the type of NULL is NULL, and false is boolean.
You can use echo gettype(''); and echogettype(NULL); to print this! The === operator not only compares values, but also compares types, so the third one is false!
So it can be said that === is equal to the following function:
functioneq($v1,$v2)
{
if($v1==$v2&&gettype($v1)
==gettype($v2)) {
return1;
} else {
return0;
}
}
So empty string (''), false, NULL and 0 are equal in value but different in type!
Note:
NULL is a special type.NULL in two cases
1. $var = NULL;
2. $var;3."", 0, "0", NULL , FALSE, array(), var $var; and objects without any attributes will be considered empty. If var is empty, TRUE is returned.
The above introduces the differences between 0, " ", null and false in PHP, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

The difference between null and NULL in C language is: null is a macro definition in C language, usually used to represent a null pointer, which can be used to initialize pointer variables, or to determine whether the pointer is null in a conditional statement; NULL is a macro definition in C language A predefined constant in , usually used to represent a null value, used to represent a null pointer, null pointer array or null structure pointer.

In JavaScript, both undefined and null represent the concept of "nothing": 1. undefined represents an uninitialized variable or a non-existent property. When a variable is declared but no value is assigned to it, the value of the variable is undefined , when accessing properties that do not exist in the object, the returned value is also undefined; 2. null represents an empty object reference. In some cases, the object reference can be set to null to release the memory it occupies.

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Both null and undefined indicate a lack of value or an undefined state. Depending on the usage scenario, there are some guiding principles for choosing to use null or undefined: 1. When you need to clearly indicate that a variable is empty or invalid, you can use null; 2. When a variable has been declared but not yet assigned a value, it will be set to undefined by default; 3. When you need to check whether a variable is empty or undefined, use the strict equality operator "===" to determine whether the variable is null or undefined. .

The difference between null and undefined is: 1. Semantic meaning; 2. Usage scenarios; 3. Comparison with other values; 4. Relationship with global variables; 5. Relationship with function parameters; 6. Nullability check; 7. Performance considerations; 8. Performance in JSON serialization; 9. Relationship with types. Detailed introduction: 1. Semantic meaning, null usually means knowing that this variable will not have any valid object value, while undefined usually means that the variable has not been assigned a value, or the object does not have this attribute; 2. Usage scenarios, etc.

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code
