Home > Backend Development > PHP Tutorial > PHP function code to determine positive integer

PHP function code to determine positive integer

WBOY
Release: 2016-07-25 08:57:14
Original
1737 people have browsed it
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";
}
?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template