Home > Article > Backend Development > What is the difference between empty and isset usage in php?
What is the difference between empty and isset usage in php? The following article will introduce to you the difference between the usage of empty function and isset function in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
isset
isset returns false only when the variable is null and returns true at any other time
( In PHP, variables are considered to be null. 1. Variables that have not been assigned or initialized. 2. Variables assigned to null)
$null = null; $num = 0; $str = ''; $bool = false; var_dump(isset($null)); // false var_dump(isset($num)); // true var_dump(isset($str)); // true var_dump(isset($bool)); // true
empty
empty determines whether the variable is empty There are 5 situations where it will return true
1, empty string ''
2, number zero 0
3, bool value false
4. null
5. String zero '0'
$null = null; $num = 0; $str = '';$bool = false;var_dump(empty($null)); // true var_dump(empty($num)); // true var_dump(empty($snum)); // true var_dump(empty($str)); // true var_dump(empty($bool)); // true
Summary:
isset only returns no value when the value is null. false
empty will determine the empty value in 5 situations
Note:The parameters of these two functions can only be variables and not constants
empty(0) empty('abc') isset(null)
This way of writing will result in an error
For more related knowledge, please pay attention to PHP Chinese website! !
The above is the detailed content of What is the difference between empty and isset usage in php?. For more information, please follow other related articles on the PHP Chinese website!