在php中empty(), is_null(), isset()三个函数都可以用来判断变量是否存在的,那么empty(), is_null(), isset()之间的区别在哪里呢,如果你不明白我一起来看看下文。
我们先来看看这3个函数的功能描述
isset 判断变量是否已存在,如果变量存在则返回 TRUE,否则返回 FALSE。
empty 判断变量是否为空,如果变量是非空 或非零 的值,则 empty() 返回 FALSE。换句话说,"" 、0 、"0" 、NULL 、FALSE 、array() 、var $var; 以及没有任何属性的对象 都将被认为是空的,如果变量为空,则返回 TRUE。
is_null 判断变量是否为NULL
怎么样,一般的都是这种解释,但这种解释已经很让人迷糊了,下面结合具体的例子来分析吧!
从中我们可以发现只要变量是""或者0,或者是false和null,只要是这些值empty都会返回true。
isset只是判断变量是否存在,只要你这个变量不是null或未赋值,返回结果都是true。若使用 isset() 测试一个被设置成 NULL 的变量,将返回 FALSE。同时要注意的是一个 NULL 字节("")并不等同于 PHP 的 NULL 常数。
而is_null正好是isset的反结果,我们可以把它看成是!isset,是isset的一个逆操作。
从以上的例子中,我们也可以得出下面这几个结论(以后编程中会经常用到的哦):
假设 $var 是任何type
当 empty($var) 为 true 时,(bool)($var) 为 false 。反之亦然。
当 is_null($var) 为 true 时,isset($var) 为 false 。反之亦然。
例如:$i=$j+1;
这里的is_null($j)为true(可以理解为因为 isset($j)为false,因为没有事先声明 $j 这个变量)
另外需要注意的两点是:
(1)empty() 只检测变量,检测任何非变量的东西都将导致解析错误 。换句话说,后边的语句将不会起作用: empty(addslashes($name))。
(2)isset() 只能用于变量,因为传递任何其它参数都将造成解析错误。若想检测常量是否已设置,可使用 defined() 函数。
概括总结isset,empty,is_null区别
刚才介绍的:检查变量,以及参数类型,这个是这3个函数不同之处的基础,也是最容易被忽视的。看到网上有很多对这个3个函数进行比较文章。很少涉及这些。下面我要说的,是在都检查已存在变量情况下,不同之处。
代码如下:
- <?php
- $a=100;
- $b="";
- $c=null;
- //isset检查
- echo "isset","$a=$a",isset($a)?"define":"www.111cN.net undefine","rn";
- echo "isset","$b=$b",isset($b)?"define":"undefine","rn";
- echo "isset","$c=$c",isset($c)?"define":"undefine","rn";
- unset($b);
- echo "isset","$b",isset($b)?"define":"undefine","rn";
- $b=0;
- echo "rnrn";
- //empty检查
- echo "empty","$a=$a",!emptyempty($a)?"no empty":"empty","rn";
- echo "empty","$b=$b",!emptyempty($b)?"no empty":"empty","rn";
- echo "empty","$c=$c",!emptyempty($c)?"no empty":"empty","rn";
- unset($b);
- echo "empty","$b",!emptyempty($b)?"no empty":"empty","rn";
- $b=0;
- echo "rnrn";
- //is_null检查
- echo "is_null","$a=$a",!is_null($a)?"no null":"null","rn";
- echo "is_null","$b=$b",!is_null($b)?"no null":"null","rn";
- echo "is_null","$c=$c",!is_null($c)?"no null":"null","rn";
- unset($b);
- echo "is_null","$b",is_null($b)?"no null":"null","rn";
通过上面这个简单测试,我们可以大体知道,当一个变量存在情况下:isset,empty,is_null检测,得到值情况了。上面没有举例更多变量。其实测试发现:
empty
如果 变量 是非空或非零的值,则 empty() 返回 FALSE。换句话说,""、0、"0"、NULL、FALSE、array()、var $var、未定义; 以及没有任何属性的对象都将被认为是空的,如果 var 为空,则返回 TRUE。
isset
如果 变量 存在(非NULL)则返回 TRUE,否则返回 FALSE(包括未定义)。变量值设置为:null,返回也是false;unset一个变量后,变量被取消了。注意,isset对于NULL值变量,特殊处理。
is_null
波比源码 » php中empty(), is_null(), isset()函数区别
levaquin 250mg sale levaquin 500mg without prescription
avodart 0.5mg price celecoxib usa zofran 4mg pill
generic aldactone valacyclovir 500mg oral order diflucan 100mg sale
order ampicillin 250mg online purchase erythromycin generic buy erythromycin 250mg sale
buy generic sildenafil 100mg robaxin 500mg ca brand methocarbamol 500mg
buy suhagra 100mg for sale order estrace 2mg pills order estradiol online cheap
lamictal oral lamictal 200mg uk retin without prescription
tadalafil 10mg pill voltaren price order diclofenac online cheap
purchase accutane generic brand azithromycin 500mg zithromax 250mg sale
buy anastrozole 1 mg generic purchase anastrozole pill order viagra 100mg generic
tadalafil 5mg generique en pharmacie viagra 100mg sans ordonnance en pharmacie acheter 25mg du viagra
cialis für frauen sildenafil 100mg kaufen für männer sildenafil 200mg kaufen ohne rezept
buy isotretinoin 40mg stromectol 12mg tablet stromectol online
doxycycline 200mg cheap order furosemide for sale buy generic lasix
order catapres for sale spiriva 9 mcg over the counter order tiotropium bromide pill
buy fosamax generic alendronate order order pepcid
imdur 20mg drug order generic digoxin micardis canada
zyban 150mg sale cheap zyban 150mg seroquel 50mg canada
molnunat 200 mg usa molnunat order prevacid without prescription
salbutamol 100 mcg ca imuran 100 mcg uk viagra 50mg for sale
order generic dapsone 100 mg purchase allegra sale buy aceon sale
medroxyprogesterone online buy biltricide for sale online periactin for sale
purchase luvox online glipizide 10mg pill order glipizide online
piracetam 800mg pills order piracetam 800 mg sale viagra 100mg uk
order zithromax pill azithromycin over the counter buy gabapentin 100mg online
cialis pills us cialis order anafranil
order chloroquine 250mg pills buy cenforce 100mg generic baricitinib pills
itraconazole online purchase sporanox generic buy tinidazole
norvasc drug order generic cialis 10mg order tadalafil 10mg online
clozapine 100mg brand decadron 0,5 mg cost brand dexamethasone 0,0,5 mg
genuine viagra genuine viagra order lisinopril 2.5mg generic
prilosec 10mg oral buy generic omeprazole best casino slots online
zyvox 600mg over the counter poker online real money casino near me
academic writing service my best friend essay writing order viagra 100mg online cheap
generic clomid 100mg clomiphene 50mg drug best online gambling sites
tadalafil 5 mg tablet cialis mail order usa viagra pharmacy
order aristocort 4mg generic buy loratadine sale purchase clarinex generic
tadalafil for sale online cialis 40mg usa order sildenafil 100mg pill
orlistat 120mg tablet buy zovirax 400mg pill acyclovir drug
cialis drug buy clopidogrel 150mg online cheap brand clopidogrel 150mg
methotrexate online order metoclopramide 20mg for sale cost metoclopramide
buy domperidone 10mg online cheap order generic tetracycline cyclobenzaprine us
order cozaar 25mg pills cozaar medication topiramate ca
oral ozobax buy toradol 10mg online toradol cost
free slots online free welcome spins no deposit real online blackjack
buy flomax 0.4mg for sale purchase ondansetron buy aldactone 100mg online cheap
purchase fluconazole for sale brand diflucan 200mg viagra without prescription
tadalafil 20mg brand female cialis cvs sildenafil 100mg oral
sildenafil online levitra or cialis tadalafil 5mg for sale
order trazodone 100mg online cheap sildenafil 50mg cheap order generic sildenafil 100mg
help me write my research paper academic writing is ivermectin 3 mg without prescription
buy sildalis without prescription sildenafil 50mg pills for men purchase lamictal pill
best slots to play online order cialis without prescription purchase tadalafil pill
order zithromax 500mg online cheap buy prednisolone 40mg pills order generic neurontin 800mg
online poker free poker online play buy modafinil pill
furosemide medication buy lasix 40mg for sale hydroxychloroquine 200mg brand
fildena over the counter buy sildenafil sale budesonide order online
cheap prednisone 10mg prednisone 40mg ca purchase mebendazole generic
buy tretinoin gel sale tadalafil 20mg sale avanafil online order
tadacip online buy tadalafil order online buy indomethacin 50mg online
terbinafine 250mg pill suprax cost amoxicillin 500mg cost
order clarithromycin 250mg purchase biaxin pill purchase antivert sale
tiotropium bromide 9mcg tablet order minocin 100mg generic terazosin cost
buy tadalafil 5mg sale Cialis order live dealer blackjack
ivermectin over counter order symmetrel 100mg sale order dapsone 100mg pill
free online slots slots casino games real casino games
essays writing order leflunomide 20mg online cheap buy azulfidine 500 mg online cheap
benicar 20mg oral oral depakote 250mg depakote price
order generic clobetasol buy buspar 10mg for sale order generic amiodarone 200mg
generic diamox imdur 40mg usa azathioprine 50mg usa
buy digoxin sale order molnunat 200mg for sale buy molnupiravir 200 mg generic
purchase carvedilol pill buy coreg 25mg online cheap buy elavil 10mg pills
cost amoxil 250mg stromectol cost ivermectin 3 mg tablet
oral dapoxetine 30mg priligy us buy domperidone
order pamelor 25 mg pills buy nortriptyline 25mg generic oral paroxetine 20mg
order indocin 50mg sale order indocin 75mg pills cenforce 100mg cost
purchase famotidine online pepcid 20mg brand mirtazapine 30mg generic
doxycycline oral aralen 250mg pill buy oral medrol
Thank you for content. Area rugs and online home decor store. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
tadacip 10mg tablet amoxicillin 500mg over the counter order amoxicillin 500mg sale
tricor generic order viagra pill sildenafil 100mg sale
buy nexium capsules biaxin for sale online buy lasix 40mg for sale
cialis for men sildenafil overnight sildenafil over counter
order cialis pill Canadian healthcare tadalafil erection pills viagra online
cost glucophage calan 240mg drug buy tamoxifen 10mg pills
buy generic provigil 200mg stromectol 6mg without prescription promethazine 25mg canada
clomiphene 50mg canada order atorvastatin 80mg online cheap prednisolone 5mg ca
prednisone 20mg for sale order prednisone 40mg pills amoxicillin pills
order fildena 100mg generic lyrica 150mg without prescription finasteride usa
overnight cialis delivery The frequent occurrence of nausea, vomiting, diarrhea, and poor oral intake, particularly during treatment, may lead to electrolyte abnormalities eg, hypokalemia, hypomagnesemia, hypocalcemia and acute kidney injury, which further increase the risk of QT prolongation
stromectol ivermectin buy order prednisone 40mg for sale buy prednisone 10mg without prescription
purchase ondansetron purchase ondansetron pills bactrim 960mg pill
purchase isotretinoin pill amoxil 500mg oral buy generic zithromax
provigil online purchase provigil without prescription buy metoprolol online cheap
buy prednisolone 40mg pills buy prednisolone 5mg without prescription buy furosemide 100mg online cheap
buy monodox for sale doxycycline 100mg for sale buy acyclovir 400mg online
azathioprine 50mg price naprosyn 500mg tablet buy naprosyn without prescription