YogeshChauhan . com

How to Check If a Variable is an Integer, a Float, a Number, NaN, an Infinite or a Numeric in PHP?

in PHP on November 19, 2019

PHP provides auto data type conversion so you can assign int value in the beginning and change it to float in the middle and PHP won't make a sound!

An integer data type is a non-decimal number between -2147483648 and 2147483647. So, any number out of that range is considered and stored as a float.

So, we need to be careful while assigning values in a lengthy program or calculation as the data type change can cause some errors. 

Here are the functions we can use to check if the number is integer.

  • is_int()
  • is_integer() 
  • is_long()

To check whether the number is float use these following functions:

  • is_float()
  • is_double()

Now, the float has it's own limit as well. If the number is greater than the PHP_FLOAT_MAX than it's infinite number. We can check that using following functions.

  • is_finite()
  • is_infinite()

To check whether the value is not a number, use this

  • is_nan()

Lastly, to check whether the variable is numeric or not, use following function

  • PHP is_numeric()

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 7 How to disable right click and drag and drop of images using jQuery? May 7 How to render Lists in React? May 7 What’s the difference between variables in CSS and SCSS (Sass)? May 7 How to define variables in SCSS (Sass)? May 7 How to show and hide an element on click in React? May 5 Use inline if to make a shorter conditional syntax in React

You might also like these

The Complete Basic Explanation of PHP SessionsPHPHow to show confirmation alerts with OK and cancel buttons using Swift 5?SwiftIntroduction to Angular modules Part 3: NgModules vs JavaScript modules and Angular librariesAngularWhat happened to your Google Analytics Tracking ID, can’t find it?MiscNumber Properties in JavaScriptJavaScriptHow to get the full URL of current page in PHP?PHPCROSS JOIN in PostgresPostgresHow services and dependency injection work in Angular?Angular5 Steps to Create a Line using Canvas Tag in HTML5HTMLHow to list all PHP variables to debug the script?PHP5 Key Principles Of Good Website UsabilityUI/UXIs Software Really Eating The World? I don’t think soMisc