26 of 410 menu

The is_numeric Function

The is_numeric function checks whether the passed value is a number or a string that can be interpreted as a number. The function returns true if the value is a number or a numeric string, and false otherwise.

Syntax

is_numeric(mixed $value): bool

Example

Let's check several values for compliance with the numeric format:

<?php var_dump(is_numeric(123)); // true var_dump(is_numeric('123')); // true var_dump(is_numeric('12.3')); // true var_dump(is_numeric('abc')); // false var_dump(is_numeric('123a')); // false ?>

Example

Let's check the operation with various numeric formats:

<?php var_dump(is_numeric(0x1A)); // true (hexadecimal) var_dump(is_numeric('0x1A')); // false (string with hexadecimal number) var_dump(is_numeric(1.2e3)); // true (exponential notation) var_dump(is_numeric('1.2e3')); // true (string with exponential notation) ?>

See Also

  • the is_int function,
    which checks if a variable is an integer
  • the is_float function,
    which checks if a variable is a floating-point number
byenru