PHP Numbers
Work with integers and floats and test numeric values.
Syntax
is_numeric($value);PHP automatically handles integers and floats. You can check numeric values with helper functions:
is_int()— is it an integer?is_float()— is it a float?is_numeric()— is it a number or a numeric string?
Example
Loading editor…
Press Run to execute the code.
When to use it
- Validate that a submitted quantity field contains a numeric value before processing an order.
- Detect whether a calculated result is a finite float before displaying it to avoid NaN or INF output.
- Use PHP_INT_SIZE to adapt number-handling logic for 32-bit vs 64-bit server environments.
More examples
Numeric type validation
is_numeric() accepts both integer and float strings, making it the first gate for user-submitted numbers.
<?php
$input = '42.5';
if (is_numeric($input)) {
$value = (float) $input;
echo "Valid number: $value";
} else {
echo 'Not a number';
}Integer and float constants
PHP's built-in numeric constants expose platform limits, useful for boundary checks and precision-aware arithmetic.
<?php
echo PHP_INT_MAX; // 9223372036854775807
echo PHP_INT_MIN; // -9223372036854775808
echo PHP_FLOAT_MAX; // 1.7976931348623E+308
echo PHP_FLOAT_EPSILON; // 2.2204460492503E-16Testing for infinite and NaN
is_infinite(), is_nan(), and is_finite() guard against non-representable float values before display or storage.
<?php
$result = log(0); // -INF
$nan = acos(2.0); // NAN
var_dump(is_infinite($result)); // true
var_dump(is_nan($nan)); // true
var_dump(is_finite(42.0)); // true
Discussion