What is difference between is_int() vs is_integer() vs is_numeric() in php?

In this article, We’ll see what is the difference between is_int(), is_integer() and is_numeric() in php?

Above functions looks like similar, but there is a difference.

is_int(): It is used to check the type of a variable is integer.

is_integer(): alias of is_int(). It is also used to test whether the type of the specified variable is an integer or not.

is_numeric(): It is used to check the variable is a number or a numeric string.

Let’s see the example:

 $variable = "12345";
 echo is_int($variable);      // return false
 echo is_integer($variable);  // return false
 echo is_numeric($variable);  // return true 

$variable is a string of numbers, not an integer value.

is_int() return false because it’s not an integer value, it’s a string.

is_numeric() return true because it’s a numeric string.

 $variable2 = 123;
 echo is_int($variable2);      // return true
 echo is_integer($variable2);  // return true
 echo is_numeric($variable2);  // return true

$variable2 is a integer value, not a string of numbers.

is_int($variable2) return true because it’s an integer value, not a string.

is_numeric($variable2) return true because it’s a number.

That’s it!. Please share your thoughts or suggestions in the comments below.

Posted in PHP

6 thoughts on “What is difference between is_int() vs is_integer() vs is_numeric() in php?

  1. Hello! This is my first visit to your blog! We are a group of volunteers and starting a new
    project in a community in the same niche. Your blog provided us valuable information to work on. You have done a wonderful job!

  2. Appreciating the hard work you put into your blog and detailed information you provide.
    It’s good to come across a blog every once in a while that isn’t the same out of date rehashed
    material. Fantastic read! I’ve saved your site and I’m including your RSS feeds to my Google account.

  3. Hi, I do believe this is a great site. I stumbledupon it 😉 I will
    revisit yet again since i have bookmarked it. Money and freedom is the best way to change,
    may you be rich and continue to help others.

Leave a Reply

Your email address will not be published. Required fields are marked *