Hey Guys....My Plugin update a few things when the player have a few coins...So....how to write that my plugin should do this between two numbers? For example: If the Player has between 15 and 400 coins something will happen... So what is the BETWEEN letter in php? Thanks Marcelo234
PHP: if($coins >= 15 && $coins <= 400) { // If amount of coins greater than 15 but less than 400 // Do stuff}
I've just edited the code, I accidentally used > and < operators. However I should have used >= and <= instead. Just to explain the difference, the latter checks if the number is equal to 15 or larger than 15 and equal to 400 but larger than 400. If you used the former the condition would not be true if the amount of coins were 15 or 400.
"between" can mean exclusively, inclusively or class boundary (min <= x < max). He didn't specify Also, in PHP 7, say, if you have two boundaries, $a and $b, and you don't want to find out which one is smaller and which one is larger, you can use the spaceship operator: PHP: $isInside = ($a <=> $x) + ($b <=> $x) === 0; If $x is less than or greater than both $a and $b, the sum would be 2 or -2. If $x is equal to one of them but not both, the sum would be 1 or -1. If $x is equal to both of them, i.e. $a has to be equal to $b, the sum would be 0, since <=> gives out 0 when they are equal. If $x is between them, one would resolve to 1 and the other would resolve to -1, so the sum would be 0. In conclusion, $isInside would be true if $a=$b=$x (disclaimer: this is not PHP syntax!), or if $x is between $a and $b but not equal to either of them (exclusively between). The <=> operator gives 1 if left operand is greater than right, 0 if equal, or -1 if left is less than right.