Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php tell if it is a positive number?

Shulou Source: shulou.com Published: 2022-06-02 15:22:39 09月30日 Update

This article is about how php determines whether it is a positive number or not. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The method of judging whether php is positive or not: 1, through regular expression to achieve judgment; 2, combined with floor function to achieve judgment; 3, through is_numeric and other functions to achieve judgment.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How can php tell if it is a positive number?

Php determines whether a variable is a positive integer.

Method 1:

If (preg_match ("/ ^ [1-9] [0-9] * $/", $amount) {die ('is a positive integer');}

Method 2:

$num ='45. 7'; if ((floor ($num)-$num)! = = 0) {exit ("not a positive integer!" );} else {exit ("is a positive integer!" );}

Method 3:

$num = '12'; if (floor ($num) = = $num) {exit ("is a positive integer!" );} else {exit ("not a positive integer!" );}

Method 4:

If (! Is_numeric ($jp_total) | | strpos ($jp_total, "." )! = = false) {die ("not an integer");} else {die ("is an integer");} Thank you for reading! This is the end of the article on "how to judge whether php is positive or not". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Integers methods positive numbers content functions more articles good practical variables articles regular environment computer see knowledge systems expressions references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux Huawei Shulou Information NVidia