PHP is_numeric() Function
Quick summary: The PHP is_numeric() function checks whether a variable is a number or numeric string.
PHP is_numeric() Syntax
is_numeric(mixed $value): bool
PHP
PHP is_numeric() Basic examples
var_dump(is_numeric("10"));
PHP
Output:
bool(true)
Numeric strings are considered numeric.
var_dump(is_numeric(10.5));
PHP
Output:
bool(true)
Floats are numeric.
PHP is_numeric() Real-world usage
$input = "42";
if (is_numeric($input)) {
echo 'Numeric input';
}
PHP
Output:
Numeric input
Validates numeric user input.
PHP is_numeric() Edge cases
var_dump(is_numeric("10abc"));
PHP
Output:
bool(false)
Alphanumeric strings are not numeric.
PHP is_numeric() Common mistakes
Using is_numeric for strict typing
is_numeric does not enforce type.
Incorrect
is_numeric("10");
Correct
is_int((int)"10");
Cast explicitly when strict typing is required.
PHP is_numeric() Frequently Asked Questions
What does is_numeric() do?
Checks if a variable is a number or numeric string.
Does it accept numeric strings?
Yes, strings like "123" or "1.5" return true.
Does it accept scientific notation?
Yes, like "1e3".
Return type?
Boolean.
Does it modify variable?
No.
Is it strict?
No, accepts strings.
Use case?
Validating numeric input.
Difference from is_int()?
is_numeric accepts strings.
Handles floats?
Yes.
Handles negative numbers?
Yes.
Handles hex?
No.
Alternative?
ctype_digit for integers.