Understanding the PHP Data Types | Data Types in PHP

Data Types in PHP

– Integer – String – Float (floating point numbers – also called double) – Boolean – Array – Object – NULL – Resource

1. PHP Integer

Integer : Integers hold only whole numbers including positive and negative numbers, i.e., numbers without fractional part or decimal point.

2. PHP String

A string can hold letters, numbers, and special characters and it can be as large as up to 2GB (2147483647 bytes maximum). The simplest way to specify a string is to enclose it in single quotes (e.g. ‘Hello world!’), however you can also use double quotes (“Hello world!”). Example echo  = 'Hello world!'; Output: Hello world!

3. PHP Float

A float (floating point number) is a number with a decimal point or a number in exponential form. Example $a = 1.234; var_dump($a); Output: float(1.234)

4. PHP Boolean

A Boolean represents two possible states: TRUE or FALSE. $x = true; $y = false;

5. PHP Array

An array stores multiple values in one single variable. In the following example $cars is an array. The PHP var_dump() function returns the data type and value:

6. PHP Object

Classes and objects are the two main aspects of object-oriented programming. A class is a template for objects, and an object is an instance of a class.

7. PHP NULL Value

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.

8. PHP Resource

The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.