Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php tell if it is a positive number?

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report