Example 1 — Numbers and Numeric Strings
Check an integer, a numeric string, a decimal string and plain text.
<?php
var_dump(is_numeric(42));
var_dump(is_numeric('42'));
var_dump(is_numeric('3.14'));
var_dump(is_numeric('abc')); How It Works
- 42 is already a number. Real integers always return true.
- '42' is a numeric string. It contains only digits, so PHP accepts it as a number.
- '3. 14' is a decimal string. A single decimal point is allowed, so the result is true.
- 'abc' has no digits. It cannot be read as a number, so the result is false.

