Is there a difference between isset
and !empty
. If I do this double boolean check, is it correct this way or redundant? and is there a shorter way to do the same thing?
isset($vars[1]) AND !empty($vars[1])
Is there a difference between isset
and !empty
. If I do this double boolean check, is it correct this way or redundant? and is there a shorter way to do the same thing?
isset($vars[1]) AND !empty($vars[1])
if we use same page to add/edit via submit button like below
then we should not use
bcoz
edit_id
is set all the time whether it is add or edit page , instead we should use check below conditionThe accepted answer is not correct.
isset() is NOT equivalent to !empty().
You will create some rather unpleasant and hard to debug bugs if you go down this route. e.g. try running this code:
https://3v4l.org/J4nBb
"Empty": only works on variables. Empty can mean different things for different variable types (check manual: http://php.net/manual/en/function.empty.php).
"isset": checks if the variable exists and checks for a true NULL or false value. Can be unset by calling "unset". Once again, check the manual.
Use of either one depends of the variable type you are using.
I would say, it's safer to check for both, because you are checking first of all if the variable exists, and if it isn't really NULL or empty.