Home > Article > Backend Development > How to determine whether a positive number is positive in php
How to judge whether a positive number is positive in php: 1. Judgment through regular expressions; 2. Judgment combined with floor function; 3. Judgment through functions such as is_numeric.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
How does PHP determine whether it is a positive number?
php determines whether a variable is a positive integer
Method one:
if(preg_match("/^[1-9][0-9]*$/" ,$amount)){ die('是正整数'); }
Method two:
$ num = '45 .7' ; if((floor($ num)- $ num)!== 0){ exit(“ 不是正整数!”); } else { exit(“ 是正整数!”); }
Method three:
$ num = '12' ; if(floor($ num)== $ num){ exit(“ 是正整数!”); } else { exit(“ 不是正整数!”); }
Method 4:
if(! is_numeric($ jp_total)|| strpos($ jp_total ,“。”)!== false){ die(“ 不是整数”); } else { die(“ 是整数”); }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether a positive number is positive in php. For more information, please follow other related articles on the PHP Chinese website!