The term "data types" refers to the classification of data in distinct
categories. PHP has a total of eight data types that we use to construct our
variables −
Integers − Whole numbers, without a decimal point, like 4195.
Doubles − Floating-point numbers like 3.14159 or 49.1.
Booleans − Have only two possible values, either true or false.
NULL − Special type that only has one value: NULL.
Strings − Sequences of characters, like 'PHP supports string operations.'
Arrays − Named and indexed collections of other values.
Objects − Instances of programmer-defined classes, which can package up
both other kinds of values and functions that are specific to the class.
Resources − Special variables that hold references to resources external to
PHP (such as database connections).
The first five are simple types, and the next two (arrays and objects) are
compound types. The compound types can package up other arbitrary
values of arbitrary type, whereas the simple types cannot.
In this chapter, let's discuss in detail about these built-in data types of PHP.
1.1 Integer Data Type in PHP
A whole number without a decimal point (like 4195) is of int type in PHP.
Integer data types are the simplest type. They correspond to simple whole
numbers, both positive and negative.
An int is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}.
An int can be represented in a decimal (base 10), hexadecimal (base 16),
octal (base 8) or binary (base 2) notation.
To use octal notation, a number is preceded with "0o" or "0O". To use
hexadecimal notation, precede the number with "0x". To use binary notation,
precede the number with "0b".
Given below are some examples −
Decimal Integer − 201, 4195, -15
Octal Integer − 0010, 0O12, -0O21
Hexadecimal Integer − 0x10, -0x100
Binary Integer − 0b10101, -0b100
Integers can be assigned to variables, or they can be used in expressions,
like so −