Home > Article > Backend Development > This article mainly shares with you several methods of determining whether a variable is empty in PHP. I hope it can help you. Whether it is empty method
This article mainly shares with you several PHP methods to determine whether a variable is empty. I hope it can help you.
Use if()
$a=1;if($a) 值为true$a='a'; if($a) 值为true$a=''; if($a) 值为false$a=0; if($a) 值为false$a=null; if($a) 值为false
empty
$a=1;if(!empty($a)) 值为true$a='a'; if(!empty($a)) 值为true$a=''; if(!empty($a)) 值为false$a=0; if(!empty($a)) 值为false$a=null; if(!empty($a)) 值为false
Comparison of several other functions
Related recommendations:
Variable type Common methods for judging variable types in php
Common methods for judging variable types in php_PHP tutorial
The above is the detailed content of This article mainly shares with you several methods of determining whether a variable is empty in PHP. I hope it can help you. Whether it is empty method. For more information, please follow other related articles on the PHP Chinese website!