简体   繁体   中英

How to write a condition if the number is equal, greater than two digits, or less than two digits

How to write a condition if the number is equal, greater than two digits, or less than two digits Example:

$n1 = 10;
$n2 = 12;

if($n1 and $n2 /*If is equal to, plus or minus two digits  */ )
  { return true; }

Example: $n1 == $n2 + 2 digits or -2 digits = true

How is this implemented in a conditional?

I am supposing you want to compare if n1 is in the range of $n2+2 or n2-2.

For that this code should work:

$n1 = 10;
$n2 = 12;

if($n1 <= $n2+2 || $n1 >= $n2-2){ 
  return true; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM