PHP is_numeric() function

In this chapter you will learn:

  1. Description for PHP is_numeric() function
  2. Syntax for PHP is_numeric() function
  3. Parameter for PHP is_numeric() function
  4. Return value for PHP is_numeric() function
  5. Example - Is it a numeric value

Description

Finds whether a variable is a number or a numeric string.

Syntax

PHP is_numeric() function has the following syntax.

bool is_numeric ( mixed $var )

Parameter

  • var - The variable being evaluated.

Return

Returns TRUE if var is a number or a numeric string, FALSE otherwise.

Example

Is it a numeric value?


<?php//from j  av a  2s .  co m
$tests = array(
    "4",
    12,
    0x29,
    0124,
    0b111001,
    137e0,
    "not numeric",
    array(),
    9.1
);

foreach ($tests as $element) {
    if (is_numeric($element)) {
        echo "'{$element}' is numeric", PHP_EOL;
    } else {
        echo "'{$element}' is NOT numeric", PHP_EOL;
    }
}
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Description for PHP is_object() function
  2. Syntax for PHP is_object() function
  3. Parameter for PHP is_object() function
  4. Return value for PHP is_object() function
  5. Example - Is it an object
Home » PHP Tutorial » PHP Data Type Functions
PHP boolval() function
PHP floatval() function
PHP gettype() function
PHP intval() function
PHP is_array(value) function
PHP is_bool() function
PHP is_float() function
PHP is_int() function
PHP is_null() function
PHP is_numeric() function
PHP is_object() function
PHP is_resource() function
PHP is_string() function
PHP isset() function
PHP settype() function
PHP strval() function