在php中判断变量为空我们有很多种方法,php为我们提供了empty,isset,var == null,is_null等等函数来进行变量判断,下面我来给大家分享这些方法的使用方法.empty() 与 isset() 的一个简单比较.
实例代码如下:
- <!–?php
- $var = 0; // 结果为 true,因为 $var 为空
- // 结果为 true,因为 $var =0
- if (emptyempty($var)) { echo '$var is either 0 or not set at all'; }
- //结果为false, 因为$var已经设置了
- if (!isset($var)) { echo '$var is not set at all'; }
- ?>
上面的empty与isset判断为没有任何属性的对象都将被认为是空.var == null
功能:判断变量是否为“空”
说明:值为 0 或 false 或 空字符串”" 或 null的变量、空数组、都将判断为 null
注意:与empty的显著不同就是:变量未初始化时 var == null 将会报错.
实例代码如下:
- $a = 0;
- $b = array();
- if ($a == null) echo '$a 为空' . "";
- if ($b == null) echo '$b 为空' . "";
- if ($c == null) echo '$b 为空' . "";
- // 显示结果为
- // $a 为空
- // $b 为空
- // Undefined variable: c
is_null实例代码如下:
- $a = null;
- $b = false;
- if (is_null($a)) echo '$a 为NULL' . "";
- if (is_null($b)) echo '$b 为NULL' . "";
- if (is_null($c)) echo '$c 为NULL' . "";
- // 显示结果为
- // $a 为NULL
- // Undefined variable: c
- 变量==0 或 变量===0
实例代码如下:
- $a ===0 $a ===""
- $a ==0 等于 $a ==""
在php url传参数时php页面的 URL 尾部参数出现 id=0 时(比如:test.php?id=0),试比较:
实例代码如下:
- if(emptyempty($id)) $id=1; // 若 id=0 ,id 也会为1
- if(!isset($id)) $id=1; // 若 id=0 ,id 不会为1
- 可分开运行以下代码检测上述推断:
- if(emptyempty($id)) $id=1;
- print $id; // 得到 1
- if(!isset($id)) $id=1;
- print $id; //得到 0
总结
在php中NULL与空是两种不同的概念,isset 主要用来判断变量是否被初始化过empty 可以将值为 “假”、“空”、“0”、“NULL”、“未初始化” 的变量都判断为TRUE
is_null 仅把值为 “NULL” 的变量判断为TRUE
var == null 把值为 “假”、“空”、“0”、“NULL” 的变量都判断为TRUE
var === null 仅把值为 “NULL” 的变量判断为TRUE
其它一些可能用到php变量判断的函数
isset($ var) : //变量是不是已经声明
empty($ var): //变量是不是为空
defined($ var): //常量是不是已经定义 define()
is_array($ var): //检验测定变量是不是是数组
is_null($ var): //检验测定变量是不是为 null
波比源码 » php 判断变量为空详解介绍
order levofloxacin 250mg sale order levaquin 500mg generic
buy avodart 0.5mg generic order flomax 0.2mg without prescription generic zofran
cheap aldactone buy propecia 1mg online cheap fluconazole medication
acillin canada generic ampicillin erythromycin 500mg sale
buy sildenafil buy tamoxifen pills robaxin price
sildenafil 50mg pill sildenafil pills 50mg brand estradiol 1mg
lamotrigine usa cheap tretinoin gel retin cream ca
order tadalafil 10mg for sale order tadalafil 20mg pills order voltaren generic
isotretinoin pills buy azithromycin sale azithromycin 250mg sale
buy indomethacin 75mg pill order lamisil sale buy amoxicillin for sale
buy tadalafil generic best medication for ed order sildenafil pills
generic arimidex anastrozole 1 mg uk cost viagra
deltasone 40mg tablet order sildenafil 100mg pill buy viagra 50mg
cialis 20mg bestellen viagra 100mg ohne rezept viagra 50mg kaufen für männer
buy isotretinoin 20mg online isotretinoin 20mg tablet stromectol for sale online
doxycycline pill purchase clomiphene buy furosemide 100mg generic
buy ramipril 5mg sale order clobetasol astelin 10ml usa
buspar 5mg drug order oxybutynin 2.5mg for sale ditropan 2.5mg without prescription
terazosin buy online buy actos 15mg generic azulfidine 500 mg canada
imdur 20mg pill imuran sale telmisartan price
zyban pills order quetiapine online quetiapine order
imuran 100 mcg without prescription pantoprazole 20mg pill viagra next day delivery usa
provera pill microzide oral cyproheptadine 4 mg sale
buy luvox 50mg glipizide 10mg without prescription glipizide 10mg brand
isotretinoin online accutane 40mg pills buy prednisone pill
piracetam tablet nootropil us purchase viagra online
brand azithromycin 500mg order gabapentin 600mg pills neurontin over the counter
cialis 5mg cost order sildenafil 50mg pill viagra sildenafil 200mg
usa cialis sales cialis 5mg sale anafranil online buy
aralen generic order olumiant without prescription buy olumiant 4mg generic
order itraconazole 100 mg pills purchase prometrium pills order generic tinidazole 300mg
order glycomet 1000mg online cheap buy atorvastatin 80mg pills tadalafil 10mg over the counter
buy olanzapine 10mg olanzapine 10mg us buy diovan online
norvasc price cialis for sale cialis without prescription
buy omeprazole 20mg generic purchase prilosec pills real poker online
linezolid 600 mg cost zyvox 600mg over the counter slot games
essay helper online blackjack casino playing poker online for money
vardenafil 20mg for sale buy vardenafil without prescription methylprednisolone us
affordable thesis writing purchase sildenafil generic viagra pills 100mg
buy clomiphene generic order generic ventolin 4mg online gambling real money
tadalafil generic name buy cialis pills oral viagra 100mg
order aristocort 10mg order triamcinolone pills buy clarinex 5mg online cheap
order generic tadalafil 40mg viagra oral sildenafil 50mg over the counter
buy orlistat diltiazem for sale order zovirax 400mg online
tadalafil 20mg brand purchase plavix order clopidogrel without prescription
methotrexate price buy methotrexate 2.5mg buy reglan generic
spins real money roulette online free online blackjack real money
buy flomax 0.4mg for sale purchase flomax online cheap order aldactone 100mg pills
cephalexin sale erythromycin 500mg without prescription erythromycin 500mg ca
tadalafil 5mg over the counter tadalafil 20mg for sale viagra usa
sildenafil 100mg cheap sildenafil for men buy tadalafil 5mg pills
order ceftin 250mg order methocarbamol 500mg pills robaxin ca
casino slots free slot games tadalafil 10mg for sale
buy trazodone 100mg pill aurogra medication sildenafil 100mg over the counter
assignment company essay writing sites order stromectol
purchase sildalis online cheap viagra sildenafil 50mg buy lamictal 200mg without prescription
deltasone 10mg ca purchase accutane online buy amoxicillin 1000mg generic
sports gambling cheap tadalafil pill cialis tadalafil
brand fildena 50mg sildenafil 100mg canada rhinocort over the counter
buy deltasone 10mg generic order mebendazole 100mg without prescription cost mebendazole 100mg
brand tretinoin buy tadalafil 20mg online avanafil over the counter
brand tadacip 10mg buy tadacip 20mg online cheap indocin over the counter
lamisil 250mg uk oral lamisil purchase trimox generic
tiotropium bromide 9mcg over the counter tiotropium bromide 9 mcg tablet terazosin tablet
proventil brand brand albuterol buy ciprofloxacin pills
actos 15mg ca actos canada purchasing viagra on the internet
cialis in usa US cialis play casino games for cash
casino free spins no deposit real money slots play slots for real money united states
free poker online online roulette for real money buy essays for college
order doxycycline 200mg pills buy albuterol 2mg buy cleocin 150mg pill
order generic diamox azathioprine online buy purchase imuran sale
coreg order buy ditropan 5mg elavil 50mg sale
amoxil 250mg for sale stromectol drug ivermectin pill cost
purchase doxycycline medrol 16mg oral methylprednisolone 4mg pills
requip 1mg brand buy rocaltrol 0.25 mg sale labetalol without prescription
oral tadacip 10mg cost tadalafil 20mg order amoxicillin 250mg online cheap
tricor online fenofibrate 200mg tablet cheap generic sildenafil
cialis online canada Generic cialis cheap sildenafil pill
purchase minocin online cheap cost minocycline purchase hytrin
purchase clomid pills prednisolone 10mg without prescription buy prednisolone 20mg sale
cost accutane 40mg buy accutane 10mg pill buy ampicillin 250mg for sale
ivermectin tablets for humans buy deltasone 20mg without prescription buy deltasone 20mg pills
buy ditropan 2.5mg online cheap order oxcarbazepine 600mg pills trileptal 600mg uk
zocor 20mg price order zocor 10mg generic order sildalis online
cheap coumadin 5mg zyloprim 100mg usa order zyloprim 300mg for sale
atorvastatin 80mg oral order viagra 50mg without prescription cheap generic viagra
femara over the counter genuine viagra viagra 50mg cheap
ivermectin 6 mg tablets order deltasone 40mg online buy accutane without a prescription
accutane order online buy isotretinoin 20mg generic order zithromax 500mg generic
clomid online levitra us cheap hydroxychloroquine 400mg
cheap levothyroxine generic order levoxyl pill vardenafil buy online
buy albenza online cheap provera 5mg price purchase medroxyprogesterone generic
buy generic zestril 10mg cost zestril 10mg lopressor 50mg cost
buy pregabalin 150mg for sale dapoxetine for sale online buy priligy 90mg generic
cheap cozaar 25mg purchase topiramate sale topamax pills
crestor 20mg cheap rosuvastatin 10mg oral domperidone 10mg oral
buy sumycin 500mg online purchase baclofen pill baclofen 10mg canada
order ranitidine 300mg online ranitidine over the counter celecoxib drug
order tamsulosin 0.2mg flomax drug order aldactone 100mg online cheap
buy betamethasone 20 gm generic oral itraconazole 100 mg itraconazole 100 mg cost
ipratropium 100mcg pills ipratropium where to buy buy linezolid
oral prometrium 100mg order progesterone online order olanzapine 10mg online cheap
starlix pills capoten 120mg cheap order candesartan generic
order zocor 10mg without prescription overnight delivery for viagra sildenafil 25 mg
carbamazepine pills cost lincocin 500 mg buy cheap generic lincocin
buy cheap generic duricef order duricef 500mg generic buy finasteride 1mg
buy diflucan without a prescription purchase fluconazole online cheap cipro over the counter
buy estrace pill buy lamotrigine without a prescription minipress 2mg sale
purchase mebendazole without prescription buy tadalafil 20mg pill order tadalis 10mg pills
cheap avanafil 200mg order avanafil 200mg generic order diclofenac 100mg online
buy nolvadex 10mg generic nolvadex cefuroxime 250mg drug
buy cheap indocin indomethacin 75mg for sale buy cefixime without prescription
bimatoprost for sale online buy careprost no prescription order trazodone 50mg online
buy trimox 250mg anastrozole 1mg oral clarithromycin 250mg oral
order catapres online cheap meclizine 25mg without prescription buy tiotropium bromide
minocycline 100mg brand hytrin 5mg ca actos ca
isotretinoin pills buy azithromycin 500mg online cheap zithromax 250mg generic
cialis mail order order sildenafil pill buy generic cialis
buy azipro generic order neurontin 100mg pill neurontin 100mg us
ivermectin 6 mg for humans stromectol 6mg uk buy deltasone online
buy furosemide cheap where can i buy furosemide albuterol uk
order levitra generic order generic plaquenil 400mg plaquenil 400mg generic
buy vardenafil generic buy tizanidine for sale buy plaquenil pills
benicar drug benicar online buy divalproex cost
buy generic temovate cost cordarone brand cordarone 200mg
order digoxin generic buy molnupiravir generic order molnupiravir 200mg pills