Integer data type in PHP

How to define a Integer variable and assign value?


The integer data type is used to specify a numeric value without a fractional component.
The range of integers in PHP is equivalent to the range of the long data type in C. On 32-bit platforms, integer values can range from -2,147,483,648 to +2,147,483,647. When you are declaring integer variable, you can declare as given below
integer $variable;

where integer denotes the type of the variable.
You can also declare variable without datatype, in such case PHP will try to determine type of variable based on the value hold by that variable. Below I have declared a variable without its type.
$variable =10;
Here the variable hold the integer value so it is of type integer.
If you want to get a type of a variable, you can use gettype() function.

Example :

print gettype($variable);

Above code will print type integer because integer(whole number) value is assigned to that variable. If you specify a number beyond the limits of the integer type then PHP automatically converts larger values to floating point numbers.

PHP Topics

Ask Questions

Ask Question