And Numbers?
So, PHP deals with numbers in a few main ways: integers, floats, and number strings — plus a couple of special types like Infinity and NaN.
If you assign a value like this:
$a = 5; // integer
$b = 5.34; // float
$c = "25"; // number string
PHP automatically figures out the type for you. You can double-check it with var_dump(), which tells you both the type and value.
Integers
An integer is any whole number — no decimal points. Think of IDs or counters in MemberPress, like $user_count = 5985;.
You can check if something’s an integer using is_int():
var_dump(is_int($user_count));
A few fun facts:
- Integers can be positive or negative.
- PHP can handle huge numbers (up to 9 quintillion on 64-bit systems).
- Once you go past that limit, PHP automatically converts it to a float.
- And, if you do math like
4 * 2.5, the result will be a float because one operand is.
There are also constants like PHP_INT_MAX, PHP_INT_MIN, and PHP_INT_SIZE — great if you’re writing something that relies on system limits.
Floats
A float is any number with a decimal or in exponential form, like 10.365 or 7.64E+5.
You can check with is_float():
$x = 10.365;
var_dump(is_float($x));
Floats can get really precise, but only up to about 14 digits before rounding errors sneak in.
PHP also defines constants like PHP_FLOAT_MAX, PHP_FLOAT_MIN, PHP_FLOAT_DIG, and PHP_FLOAT_EPSILON — the last one’s especially nerdy; it’s the tiniest value PHP can distinguish from 1.0.
Infinity
If a number goes beyond what PHP can handle — say, dividing something by zero or using 1.9e411 — PHP calls it infinity.
You can check with is_infinite().
$x = 1.9e411;
var_dump(is_infinite($x));
Basically, it’s PHP’s way of saying “this number is too big for me, mate.”
NaN (Not a Number)
NaN appears when you try something mathematically impossible, like:
$x = acos(8);
var_dump($x); // NaN
So if you ever see NaN in your debug logs — it’s PHP politely telling you your math makes no sense 😅.
Numerical Strings
Sometimes you’ll have a number as a string, like something coming from a form input ("5985").
You can use is_numeric() to check if it’s numeric or not:
$x = "59.85" + 100;
var_dump(is_numeric($x)); // true
But note: since PHP 7, hex strings like "0xf4c3b00c" are not considered numeric anymore.
Casting
You can convert numbers between types manually using casting:
$x = 23465.768;
$int_cast = (int)$x; // becomes 23465
$x = "23465.768";
$int_cast = (int)$x; // becomes 23465
It’s useful when you want to make sure you’re working with an integer — say, when dealing with IDs, timestamps, or any place where decimals don’t make sense.