Learn the PHP Data type feature with their eight primitive PHP data types: Integer, Floating point number or Float, String, Booleans, Array, Object, resource and NULL.

All data types are used to construct a variable.

Data Type: Variables can store data of different types, and different types of data can do different things.

For example:

You can add variables easily whose values are number e.g:(1 + 2)
But Adding two variable whose values are character is no use at all e.g: (a + b)

Our Previous PHP tutorial if you missed :

PHP supports eight primitive types:

  • Four scalar types:
  • Tow Compound types:
  • Finally Two special characters:

1)   PHP Integer data type:

An Integer is a set of number. You can usually use any number from –2 billion up to +2 billion. Without a decimal point, like, -10, 20, +5. They are the simplest type they correspond to simple whole numbers, both positive and negative. Integers can be assigned to variables, or they can be used in expressions, like so:
Syntax with Example:

An Integer can be in decimal (base 10), octal (base 8), and hexadecimal (base 16) format. Decimal format is the default, octal integers are specified with a leading 0, and the hexadecimals have a leading 0x.

2)   PHP Boolean data type:

Boolean data types represent two possible states: — TRUE or FALSE. Boolean are often used in conditional testing. You will learn more about this Latter.
Syntax example:


Interpreting other types as Booleans:
Here are the rules for determine the “truth” of any value not already of the Boolean type:

a>If the value is a number, it is false if exactly equal to zero and true otherwise.
Type of NULL value always false.
Doesn’t use double as Boolean.
b>If the value is a string, it is false if the string is empty (has zero characters) or is the string “0”, and is true otherwise.
c>If the value is an array, it is false if it contains no other values, and it is true otherwise. For an object, containing a value means having a member variable that has been assigned a value.

3)  PHP Float data type:

A float is number with decimal point (floating point number). They like 3.14159 or 49.1. By default, doubles print with the minimum number of decimal places needed. Doubles and float both are similarly same. However, have small different. FLOATS store floating-point numbers with 8-place accuracy and take up 4 bytes. DOUBLES store floating-point numbers with 16-place accuracy and take up 8 bytes.



4)  PHP Strings data type: 

A string is a sequence of letters, numbers, special characters and arithmetic values or combination of all.
Where every Character is same as a byte.
A string can be any text inside quotes. User can use single or double quotes.
A string can hold large dates up to 2GB (2147483647 bytes maximum).



You will learn more about strings later in this tutorial.

5)   PHP Array data type: 

An array is a variable that can grip more than one value at a time. Arrays are useful when you want to store a group of data. PHP’s arrays are actually maps (each key mapped to a value).


In the above example, we made use of the key / value structure of an array. The keys were the numbers we specified in the array and the values were the names of the Cars. Each key of an array represents a value that we can manipulate and reference. The general form for setting the key of an array equal to a value is:


You will learn more about array data type later in this tutorial.

6)   PHP NULL data type: 

Null is a special data type which can have only one value: NULL.
A variable of data type NULL is a variable that has no value assigned to it.


7)  PHP Resource data type:

The special Resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.
A common example of using the resource data type is a database call. For more on resource data type please keep reading our tutorial.We will publish soon.Thanks

=>> If you preparing for PHP developer job interview then please click to get all latest PHP inerview question