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. .
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('content-type:text/html;charset=utf-8'); $a = 10; $b = 8; if($a > $b){ echo '$a 大于 $b<br>'; }else{ echo '$a 小于 $b<br>'; } ?>
Method 2: Use the comparison function strcmp()
strcmp() function can compare two Binary-safe comparison of strings.
strcmp(数1, 数2)
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('content-type:text/html;charset=utf-8'); echo strcmp(1, 2)."<br>"; echo strcmp(23, 2)."<br>"; echo strcmp(1, 1)."<br>"; ?>
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!