In php, ($myvariable==0)
When $myvariable is zero, the value of the expression is true; when $myvariable is null, the value of this expression is also true. How can I exclude the second case? I mean I want the expression to be true only when $myvariable is zero. Of course I can write
($myvariable!=null && $myvariable==0 )
but is there other elegant way to do this?
If your zero could be a string, you should also considere checking the "zero string"
I hade faced a similar issue in one of my projects, with a minor difference that I was also using the values ZERO as a valid value for my condition. here's how I solved it using simple logic to separate NULL from zero and other values.
read more about comparison operators.
There's an
is_null
function, but this will just replace your$myvariable!=null
Try
($myvariable === 0)
which will not perform type coercion.