# PHP Integer Data Type

PHPServer Side ProgrammingProgramming

## Definition and Usage

In PHP, Integer is a scalar data type that represents a numeric constant represents a whole number wihout any fractional part. PHP allows an integer to be expressed in decimal, hexadecimal, octal or binary number system by prefixing appropriate symbol.

By default Integer is assumed in decimal notation. For Hexadecimal, octal and binary number system, respectively 0x, 0 an 0b symbols are prefixed.

## Syntax

<?php
//Literal assignment of integer value to variable
$var=232; // Decimal$var1=045; // Octal
$var2=oxB2; //hexadecimal$var3=0b1001; //binary
?>

For better readibility, integer literal may use "_" as separation symbol which will be omitted by PHP scanner while processing.

<?php
$var=55_467; // it will treated as 55467 ?> ## PHP Version Use of separation symbol "_" is avilable since PHP 7.40 Following example shows integer literal representation in different notations. ## Example Live Demo <?php$var=10;
echo "decimal : " .$var . "\n"; //Octal number$var1=010;
echo "Octal: " . $var1 ."\n"; //Hexadecimal number$var2=0x10;
echo "hexadecimal : " . $var2 . "\n"; //binary number$var3=0b10;
var_dump(\$var);
?>

## Output

This will produce following result −

float(9.2233720368548E+18)
Updated on 19-Sep-2020 14:38:43