Is_Numeric () PHP Function

No replies
jose
jose's picture
User offline. Last seen 43 weeks 10 hours ago. Offline
Joined: 03/30/2009

When we want to know if a values is a number we should use is_numeric() function within a if statement. This function returns true is numeric or false if is not.

if (is_numeric(777)){
   echo "is numeric";
}else{
   echo "is not a number";
}

//returns "is a numeric"

if (is_numeric('hello')){
   echo "is numeric";
}else{
   echo "is not a number";
}

//returns "is not a number"