Home > Backend Development > PHP Tutorial > Introduction to the functions is_null, isset, empty in php

Introduction to the functions is_null, isset, empty in php

一个新手
Release: 2023-03-16 08:50:01
Original
1827 people have browsed it

These three functions are easy to confuse in PHP, but they are often encountered during development and written interviews. Let’s summarize them here.

When the variable $a=null, the program result is

is_null($a) true

##isset($a )

false

empty($a)

true

Program result when variable $a=''(empty string) For

is_null($a)

false##isset($a)

trueempty($a)

true

When variable $a= ' ' (there is a space in the middle), the program result is

is_null($a)

false

isset($a)

true

empty($a)

false

When the variable $a=[] (empty array) the program result is

is_null($a)

false

##isset($a) true

empty($a) true

So we concluded:

1.is_null is only true for null and all others are false. In php, null is a variable that has neither type nor value.

2.isset is only false for null and the others are all t because '',' ', [], these three variables have clear data types, '' represents an empty string, ' ' represents a space string, [] represents an empty array. Therefore, a variable is true as long as it has type isset.

3.empty is false only for non-empty arrays and strings.

The above is the detailed content of Introduction to the functions is_null, isset, empty in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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