【发布时间】:2013-02-19 13:50:13
【问题描述】:
在一个 PHP sn-p here 网上看到了这个。
/**
* @param string $str subject of test for integerness
* @return bool true if argument is an integer string
*/
function intStr($str) {
return !!preg_match('/^\d+$/', $str);
}
运行这段代码 sn-p 产生:
> var_dump( intStr("abc") );
bool(false)
> var_dump( intStr("123") );
bool(true)
问题:
双感叹号是一个有效的操作符,还是和“not-not”一样,它自己否定?
还有,为什么这个运算符要与
preg_match函数结合使用?
【问题讨论】:
-
cmets 说明一切:@return bool true [...]