search
HomeBackend DevelopmentPHP TutorialIn-depth understanding of the relationship between 0, null, empty, empty, false, and strings in PHP

  1. //Judge the relationship between 0 and '' and empty null false start//

  2. if('safdasefasefasf'==0) {

  3. echo "The string is converted into a number equal to 0
    ";
  4. }//output: The string is converted into a number equal to zero.
  5. This is a key example

  6. The manual explains: The value is determined by the first part of the string. If the string begins with legal numeric data, that number is used as its value, otherwise its value is 0 (zero).

  7. In other words, '3asfdf'==3 ; 'adsfasdf'==0 Be very careful

  8. $a=0;

  9. if($a= =''){
  10. echo "0 is equal to ''
    ";
  11. } //output:0 is equal to ''
  12. if(trim($a)==''){
  13. echo "trim(0 ) is equal to ''
    ";
  14. } //no output
  15. if($a===''){

  16. echo "0===''
    ";
  17. } //no output
  18. if(empty($a)){
  19. echo "'' is empty
    ";
  20. } //output:'' is empty
  21. if(is_null ($a)){
  22. echo "0 is null
    ";
  23. } //no output
  24. if(is_numeric($a)){
  25. echo "0 is numeric
    ";
  26. } //output:0 is numeric
  27. if(is_string($a)){
  28. echo "0 is string
    ";
  29. } //no output
  30. if(strval($a)==' '){
  31. echo "0 converted into a string is ''
    ";
  32. } //no output
  33. // Determine the relationship between 0 and '' and empty null false end //> ;
  34. // Determine the relationship between '' and 0 and empty null false start //

  35. $b = '';

  36. if($b==0){
  37. echo "'' is equal to 0
    ";
  38. } //output:'' is equal to 0
  39. if(!''){
  40. echo "'' is false
    ";
  41. } // output:'' is false
  42. if(!0){
  43. echo "0 is false
    ";
  44. } //output:0 is false bbs.it-home.org
  45. // Judge '' and The relationship between 0 and empty null falseend //
  46. echo "Be careful when judging empty (''), 0 is also equivalent to '', 0 and '' are both equivalent to empty Characters and false, it is best to use ===";

  47. ?>
Copy the code

Output results: 0 is equal to " " is empty 0 is numeric " is equal to 0 " which is false. 0 is false. Be careful when judging empty ("). 0 is also equivalent to ". 0 and " are both equivalent to empty characters and false, and are judged to be empty. It is best to use === and can only be explained this way: 0 is also equivalent to ", 0 and " are equivalent to the null character and false. Be careful when judging empty ("). 0 is also equivalent to ", 0 and " are equivalent to empty characters and false. It is best to use === when judging empty;

echo 0 == null; echo '**
' ; //true echo 0 === null; echo '**
' ; //false echo (string)0 != null; echo '**
' ; //true echo 0 != null; echo '**
' ; //false echo 0 !== null; echo '**
' ; //true


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
c语言中null和NULL的区别是什么c语言中null和NULL的区别是什么Sep 22, 2023 am 11:48 AM

c语言中null和NULL的区别是:null是C语言中的一个宏定义,通常用来表示一个空指针,可以用于初始化指针变量,或者在条件语句中判断指针是否为空;NULL是C语言中的一个预定义常量,通常用来表示一个空值,用于表示一个空的指针、空的指针数组或者空的结构体指针。

PHP判断某个数组中是否存在指定的keyPHP判断某个数组中是否存在指定的keyMar 21, 2024 pm 09:21 PM

这篇文章将为大家详细讲解有关PHP判断某个数组中是否存在指定的key,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。PHP判断某个数组中是否存在指定的key:在php中,判断某个数组中是否存在指定的key的方法有多种:1.使用isset()函数:isset($array["key"])该函数返回布尔值,如果指定的key存在,则返回true,否则返回false。2.使用array_key_exists()函数:array_key_exists("key",$arr

undefined和null是什么意思undefined和null是什么意思Nov 20, 2023 pm 02:39 PM

在JavaScript 中,undefined和null都代表着“无”的概念:1、undefined 表示一个未初始化的变量或一个不存在的属性,当声明了一个变量但没有对其赋值时,这个变量的值就是undefined,访问对象中不存在的属性时,返回的值也是undefined;2、null表示一个空的对象引用,在某些情况下,可以将对象的引用设置为null,以便释放其占用的内存。

什么时候用null和undefined什么时候用null和undefinedNov 13, 2023 pm 02:11 PM

null和undefined都表示缺少值或未定义的状态,根据使用场景的不同,选择使用null还是undefined有以下一些指导原则:1、当需要明确指示一个变量为空或无效时,可以使用null;2、当一个变量已经声明但尚未赋值时,会被默认设置为undefined;3、当需要检查一个变量是否为空或未定义时,使用严格相等运算符“===”来判断变量是否为null或undefined。

null和undefined有什么不同null和undefined有什么不同Nov 08, 2023 pm 04:43 PM

null和undefined的区别在:1、语义含义;2、使用场景;3、与其它值的比较;4、与全局变量的关系;5、与函数参数的关系;6、可空性检查;7、性能考虑;8、在JSON序列化中的表现;9、与类型的关系。详细介绍:1、语义含义,null通常表示知道这个变量不会拥有任何有效的对象值,而undefined则通常表示变量未被赋值,或者对象没有此属性;2、使用场景等等。

PHP函数介绍—empty(): 检查变量是否为空PHP函数介绍—empty(): 检查变量是否为空Jul 25, 2023 am 10:23 AM

PHP函数介绍—empty():检查变量是否为空在PHP编程中,经常需要对变量进行判断,判断变量是否为空是一个常见的需求。而PHP内置的empty()函数就是用来检查变量是否为空的。本文将介绍empty()函数的用法以及提供一些实际的代码示例。empty()函数的用法非常简单,它接受一个参数,并返回一个布尔值。当参数的值为以下情况之一时,empty()函数

java中null的用法有哪些java中null的用法有哪些Mar 01, 2024 am 10:10 AM

用法:1、将引用类型的变量初始化为null,表示该变量当前不指向任何对象;2、将引用类型的变量设置为null,可以释放该变量所引用的对象的内存空间,帮助垃圾回收器回收该对象;3、使用null来检查一个引用是否为空,可以通过判断引用是否为null来避免NullPointerException异常的发生;4、在条件判断中使用null,可以判断某个引用是否为空。

php 数组怎么去掉nullphp 数组怎么去掉nullDec 23, 2022 am 10:27 AM

php数组去掉null的实现方法:1、使用“foreach( $arr as $k=>$v){...}”方法去掉数组的空值;2、使用while语法结构去除空值;3、使用array_filter函数对数组进行过滤,去掉空值即可。

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
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

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.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool