Data Types in PHP
The values assigned to a PHP variable may be of different data types including simple string and numeric types to more complex data types like arrays and objects.
PHP supports a total of eight primitive data types: Integer, Floating point number or Float, String, Booleans, Array, Object, resource, and NULL. These data types are used to construct variables. Now let's discuss each one of them in detail.
PHP Integers
Integers are whole numbers, without a decimal point (..., -2, -1, 0, 1, 2, ...). Integers can be specified in decimal (base 10), hexadecimal (base 16 - prefixed with 0x
) or octal (base 8 - prefixed with 0
) notation, optionally preceded by a sign (-
or +
).
<?php $a = 123; // decimal number var_dump($a); echo "<br>"; $b = -123; // a negative number var_dump($b); echo "<br>"; $c = 0x1A; // hexadecimal number var_dump($c); echo "<br>"; $d = 0123; // octal number var_dump($d); ?>