Steven Steven -4 years ago 114
PHP Question

PHP considers null is equal to zero

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?

Answer Source
$myvariable === 0

read more about comparison operators.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download