• PHP Video Tutorials

PHP - is_numeric() Function


Advertisements

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

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements