Tags

Zero is not null, and null is not zero.
But how to identify it from json decoder ?

Solution: === Operator will compare types

$json = ‘{“a”:null,”b”:0,”c”:{“data”:0,”value”:null},”d”:4,”e”:5}’;
echo “->A = “.$obj->a.”
“; // no data
echo “->B = “.$obj->b.”
“; // 0
if ($obj->a === null) {
echo “->A is null
“; // ->A is null
}
if ($obj->b !== null) {
echo “->B is not null
“; // ->B is not null
}

Advertisements