如何检查语句中变量是否为整数?
就像字符串一样,我们可以说:
if i == " "
return something
我怎么说:if i == integer
??
答案 0 :(得分:2)
赞:
grep -oP "^10.9.0.*,wq$1-\K.*" | cut -d, -f1 | sort
或者这样:
String.prototype.hashCode = function() {
var hash = 0,
i, chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
您将在此处找到更多信息:What's the canonical way to check for type in Python?(我认为您的问题是重复的)
答案 1 :(得分:0)
使用isinstance
:
foreach($course_cat->result() as $c){
if ($c->no_of_events == 0) {
continue;
}
echo "<td>".$c->no_of_events."</td>";
$total_events += $c->no_of_events;
}