How to determine whether a positive number is positive in php

藏色散人
Release: 2023-03-13 20:08:01
Original
3622 people have browsed it

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.

How to determine whether a positive number is positive in php

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('是正整数');
}
Copy after login

Method two:

$ num = '45 .7' ;
if((floor($ num)- $ num)!== 0){
  exit(“ 不是正整数!”);
} else {
  exit(“ 是正整数!”);
}
Copy after login

Method three:

$ num = '12' ;
if(floor($ num)== $ num){
  exit(“ 是正整数!”);
} else {
  exit(“ 不是正整数!”);
}
Copy after login

Method 4:

if(! is_numeric($ jp_total)|| strpos($ jp_total ,“。”)!== false){
  die(“ 不是整数”);
} else {
  die(“ 是整数”);
}
Copy after login

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!

Related labels:
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