Which is the more effective way of checking whether $value
is not null
if ($value > 0 && $value !== 'null') { }
or
if (empty($value)) { }
Which is the more effective way of checking whether $value
is not null
if ($value > 0 && $value !== 'null') { }
or
if (empty($value)) { }
PHP has an elegant is_null
function to check if a variable is actually NULL
.
if (is_null($value)) {
// so something
}
empty
, on the other hand, checks for empty strings (''
), zeroes (as integers, floating points or even the string '0'
), FALSE
, empty arrays, uninitialized variables and NULL
s.
if(!empty($value)){
//do stuff
}else{
// do somthing else
}