1. Home
  2. Computing & Technology
  3. PHP / MySQL

Is_Numeric () PHP Function

By Angela Bradley, About.com

Definition: The is_numeric () function is used to check if a value is a number. This could be used within an if () statement to treat numbers in one way and non-numbers in another. It will return true or false. Numeric strings consist of an optional sign (such as + or -), any number of digits, optional decimal point and optional exponent. It will also identify a hexadecimal number, but only on its own without a sign, decimal or exponent.
Also Known As: Is Numeric, Is Number
Examples:
<?php
if (is_numeric (887))
{
echo "Yes";
} else {
echo "No";
}
?>

Since 887 is a number, this should echo "Yes"

<?php
if (is_numeric ("cake"))
{
echo "Yes";
} else {
echo "No";
}
?>

Since cake is not a number, this should echo "No"

Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. PHP Is_Numeric - Check if a PHP variable is a number

©2009 About.com, a part of The New York Times Company.

All rights reserved.