I have encounterted a strange bug when I dealt with a comparision in php.
$tmp = 0;
$result = null;
$tmp == null ? $result="surprise" : $result="normal";
print_r($result);
?>
What's the output in your front? It's "surprise"! The php convert 0 to null for the equality comparison. You shouldn't compare the null and 0. What should we do if we really want to compare them. Don't worry. There is a simple way to do it. The next codes will complete the comparision as you want.
$tmp = 0;
$result = null;
$tmp === null ? $result="surprise" : $result="normal";
print_r($result);
?>
So does the string with the length zero.
阅读(1960) | 评论(0) | 转发(0) |