PHP将0检查为false [重复]

This question already has an answer here:

I am creating a cropping algorithm and at some point checking if values exists through

if($x && $y){ //then crop }

Which checks if the initial coordinates of the cropping area are specified. However, this fails at the boundaries, because if any of the values are zero (cropping from the border), then php evaluates it as false.

How can I overcome that?

</div>

Use isset() to check if a variable is set and is not NULL:

if(isset($x) && isset($y)) { //then crop }

Use === and !== to compare both type and value.

For example:

if($x !== false && $y !== false)