Yogesh Chauhan's Blog

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 add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Pagination in CSS with multiple examplesCSSIntroduction to components and templates Part 1: Component MetadataAngularRelative Length Units in CSSCSSSolution to Precision Problem in JavaScript NumbersJavaScriptA Quick Comparison of JOIN and Subquery in SQLSQL/MySQLSelf-Driving and Intelligent NetworksMiscellaneousHow to create a vertically rotating texts using CSS?CSSA complete diagram with building blocks of an Angular applicationAngularEverything you need to know about ANY, SOME and ALL Operators in PostgresPostgresAggregate Functions Examples in Postgres for BeginnersPostgresWhat is Object Mutability in JavaScript?JavaScriptUPDATE and DELETE Statements in PostgresPostgres