", "<=" or ">=", for example "$a>$b", if "$a" is greater than "$b", TRUE will be 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."/> ", "<=" or ">=", for example "$a>$b", if "$a" is greater than "$b", TRUE will be 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.">

Home >Backend Development >PHP Problem >How to determine the size of several numbers in php

How to determine the size of several numbers in php

青灯夜游
青灯夜游Original
2022-04-15 20:25:564539browse

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;;
}
?>

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)

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

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

  • 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>";
?>

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!

Statement:
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