PHP Numbers

PHP Numbers

In PHP, there are two primary numeric data types: Integers and Floats.

PHP provides automatic data type conversion. So, if you assign an integer value to a variable, the type of that variable will automatically be an integer. Then, if you assign a string to the same variable, the type will change to a string!


PHP Integers

An integer is a number without any decimal part.

PHP has built-in functions to check if the type of a variable is integer:

Example

<?php
$x = 5985;
var_dump(is_int($x)); // Returns bool(true)
?>

PHP Floats

A float is a number with a decimal point or a number in exponential form. To check if a number is a float, you can use is_float() or is_double().

PHP is_numeric()

The is_numeric() function can be used to find whether a variable is a number or a numeric string. It is widely used in web forms to validate user inputs.