因为POST输入的是字符串,所以不能用is_int来判断是否为整数,首先通过is_numeric()来判断是否为数字或者数字字符,然后判断是否存在小数点;
$num = '10.0'; // 是否为数字或者数字字符 if(is_numeric($num)){ // 是否包含小数点 if(strpos($num,'.')===false){ // 不包含小数点为整数 echo 'This is int'; }else{ echo 'This is float'; } }else{ echo 'This is not number'; }
Leave a Reply