How to determine the size of several numbers in php

青灯夜游
Release: 2023-03-15 18:24:01
Original
4486 people have browsed it

Judgment method: 1. Use comparison operators "", "=", for example "$a>$b", if "$a " is greater than "$b", then TRUE is returned; 2. Use the comparison function strcmp(), the syntax is "strcmp(number 1, number 2)". If the return value is greater than 0, then number 1 is greater than number 2. If 0 is returned, the two numbers are equal. .

How to determine the size of several numbers in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php determines the size of several numbers

Method 1: Use the comparison operators "", " =”

Example Name Description
$a < ; $b 小与 If the value of $a is less than the value of $b, return TRUE, otherwise return FALSE
$a > $b is greater than If the value of $a is greater than the value of $b, return TRUE, otherwise return FALSE
$a Less than or equal If the value of $a is less than or equal to the value of $b, return TRUE, otherwise return FALSE
$a > = $b Greater than or equal If the value of $a is greater than or equal to the value of $b, return TRUE, otherwise return FALSE

Example:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$a = 10;
$b = 8;
if($a > $b){
    echo &#39;$a 大于  $b<br>&#39;;

}else{
    echo &#39;$a 小于 $b<br>&#39;;
}
?>
Copy after login

How to determine the size of several numbers in php

Method 2: Use the comparison function strcmp()

strcmp() function can compare two Binary-safe comparison of strings.

strcmp(数1, 数2)
Copy after login

The strcmp() function will return different values ​​based on the comparison result:

  • If number 1 is less than number 2 , then return value < 0;

  • If number 1 is greater than number 2, then return value > 0;

  • If number 1 is equal to number 2, then 0 is returned.

Example:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
echo strcmp(1, 2)."<br>";
echo strcmp(23, 2)."<br>";
echo strcmp(1, 1)."<br>";
?>
Copy after login

How to determine the size of several numbers in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine the size of several numbers 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!