How to find whether a variable is numeric or not in PHP?

The PHP is_numeric() function can be used to find whether a variable is numeric. The function returns true if the variable is a number or a numeric string, false otherwise.


$x = 5985; var_dump(is_numeric($x)); 
//true 

$x = "5985"; var_dump(is_numeric($x));
 //true 

$x = "59.85" + 100; 
var_dump(is_numeric($x)); 
//true

$x = "Hello"
 var_dump(is_numeric($x)); 
//false

Comments

Leave a Reply