Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1675174
  • 博文数量: 20
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 3272
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-04 09:45
文章分类

全部博文(20)

文章存档

2011年(3)

2010年(1)

2009年(1)

2008年(15)

我的朋友

分类: LINUX

2008-03-06 17:42:13

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) |
给主人留下些什么吧!~~