Home >Backend Development >PHP Tutorial >PHP function code to determine positive integer
This article shares a PHP function that is used to detect whether a certain value is a positive integer. Friends in need can refer to it.
When doing PHP development, especially when it comes to product IDs or information category IDs, integer detection needs to be done. Whether you believe it or not, I believe it anyway, ha. Let’s look at the specific implementation code: <?php //判断是否是正整数 //by bbs.it-home.org function check_zzs($varnum){ $string_var = "0123456789"; $len_string = strlen($varnum); if(substr($varnum,0,1)=="0"){ return false; die(); }else{ for($i=0;$i<$len_string;$i++){ $checkint = strpos($string_var,substr($varnum,$i,1)); if($checkint===false){ return false; die(); } } return true; } } //by bbs.it-home.org //调用示例 $intValue = 233; if(check_zzs($intValue)){ echo "ok"; } ?> |