1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

# Numbers between Numbers

Comments in 'Plugin Development' started by Marcelo234, Jan 30, 2016.

1. Offline

### Marcelo234New Member

Joined:
Oct 18, 2014
Posts:
204
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
2. Offline

### DinokillerNotable Member

Joined:
Sep 22, 2013
Posts:
376
Minecraft User:
PHP:
``` if(\$coins >= 15 && \$coins <= 400) { // If amount of coins greater than 15 but less than 400    // Do stuff} ```
Last edited: Jan 31, 2016
3. Offline

### DinokillerNotable Member

Joined:
Sep 22, 2013
Posts:
376
Minecraft User:
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.
4. Offline

### KubixQActive Member

Joined:
Sep 13, 2015
Posts:
85
Minecraft User:
Basics, but all people can don't know that. xD
5. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
"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.
Last edited: Feb 2, 2016
PocketKiller and minebuilder0110 like this.
6. Offline

### DinokillerNotable Member

Joined:
Sep 22, 2013
Posts:
376
Minecraft User:
Interesting, is the spaceship operator exclusive to PHP or can it be found in other languages?
7. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User: