search
Homephp教程php手册php中is_null,empty,isset,unset 的区别详细介绍

php中is_null,empty,isset,unset 的区别详细介绍

Jun 13, 2016 am 11:53 AM
emptyissetnullphpunsetintroducethe differenceofdetailed

is_null, empty, isset, unset 我们先来看看这4个函数的描述。

isset 判断变量是否已存在(配置)
unset 把变量删除(释放)掉
empty 判断变量是否为空
is_null 判断变量是否为NULL
ok,已经开始搞人了。那么开始,这4个函数中除了unset,其他3个都是判断函数,unset首先出局,因为他不会搞错,其次是is_null,我们可以把它看成是!isset,是isset的一个逆操作,下面一张表可以很清楚的说明他们之间的关系:

复制代码 代码如下:


变量                          empty          is_null          isset
 $a=””                       true               false              true
 $a=null                     true               true              false
 var $a                      true              true               false
 $a=array()               true               false              true
 $a=false                   true               false              true
 $a=15                      false              false               true
 $a=1                        false              false               true
 $a=0                        true               false               true
 $a=”0”                     true               false                true
 $a=”true”                false               false              true
 $a=”false”               false               false               true



从中我们可以发现只要变量是否为” “或者0,或者是false和null,只要是这些值empty都会返回true,而isset是判断变量是否存在,只要你这个变量不是null或未赋值,返回结果都是true,而is_null正好是isset的反结果。

当然如果只是想做如下工作:
echo !isset($_GET['a']);  //如果得不到变量a的值
echo empty($_GET['a']);  //如果变量a的值是空

那么结果都是一样的,都可以用。

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

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment