• PHP Video Tutorials

PHP - is_numeric() Function



Definition and Usage

The function is_numeric() verifies whether a variable is a number or a numeric string.

Syntax

bool is_numeric ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The variable value to be evaluated

Return Values

This function returns true if value is a number or a numeric string, false otherwise.

Dependencies

PHP 4 and above.

Example

Following example demonstrates return values with different types of variables −

<?php
   $test_variable = array(
      "21",
      1443,
      0x539,
      01341,
      0b10100111001,
      1337e0,
      "0x539",
      "01341",
      "0b10100111001",
      "1337e0",
      "tutorialspoint",
      array(),
      9.1,
      null,
      '',
   );

   foreach ($test_variable as $var) {
      if (is_numeric($var)) {
         echo $var . " is numeric <br>";
      } else {
         echo $var. " is NOT numeric<br>";
      }
   }
?>

Output

This will produce following result −

21 is numeric
1443 is numeric
1337 is numeric
737 is numeric
1337 is numeric
1337 is numeric
0x539 is NOT numeric
01341 is numeric
0b10100111001 is NOT numeric
1337e0 is numeric
tutorialspoint is NOT numeric
Array is NOT numeric
9.1 is numeric
is NOT numeric
is NOT numeric
php_variable_handling_functions.htm
Advertisements