PHP Data Types
Last Updated : 16 Jan 2026
This PHP data types chapter is a fundamental concept of how to define variables and store and manipulate data. Variables hold different types of data or values. PHP is known as a loosely typed programming language, meaning do not need to specify the data type to declare a variable. PHP supports 8 primitive data types that can be categorized further in 3 types:
Data Types Example
Here is a simple data type example that will help you in getting the data type of any object using the var_dump() function.
Example
Output:
Float(10)
The table given below describes all the data types in details
| PHP Data Types | Description | Types |
|---|---|---|
| Scalar Types | It holds only single value | There are 4 scalar data types in PHP: 1. Boolean 2. Integer 3. Float 4. String |
| Compound Types | It can hold multiple values | There are 2 compound data types in PHP: 1. Array 2. Object |
| Special Types | Unique types in PHP | 1. Resource 2. NULL |
Scalar Types
PHP Boolean
Booleans are the simplest data type works like switch. It holds only two values: TRUE (1) or FALSE (0). It is often used with conditional statements. If the condition is correct, it returns TRUE otherwise FALSE.
Example
Output:
This condition is TRUE.
PHP Integer
Integer means numeric data with a negative or positive sign. It holds only whole numbers, i.e., numbers without fractional part or decimal points.
Rules for integer:
- An integer can be either positive or negative.
- An integer must not contain decimal point.
- Integer can be decimal (base 10), octal (base 8), or hexadecimal (base 16).
- The range of an integer must be lie between 2,147,483,648 and 2,147,483,647 i.e., -2^31 to 2^31.
Example
Output:
Decimal number: 34 Octal number: 163 HexaDecimal number: 69
PHP Float
A floating-point number is a number with a decimal point. Unlike integer, it can hold numbers with a fractional or decimal point, including a negative or positive sign.
Example
Output:
Addition of floating numbers: 73.812
PHP String
A string is a non-numeric data type. It holds letters or any alphabets, numbers, and even special characters.
String values must be enclosed either within single quotes or in double quotes. But both are treated differently. To clarify this, see the example below:
Example
Output:
Hello Tpointtech Hello $company
Compound Types
PHP Array
An array is a compound data type. It can store multiple values of same data type in a single variable. Here is given an example:
Example
Output:
array(3) { [0]=> string(13) "Royal Enfield" [1]=> string(6) "Yamaha" [2]=> string(3) "KTM" }
Array Element1: Royal Enfield
Array Element2: Yamaha
Array Element3: KTM
You will learn more about array in later chapters of this tutorial.
PHP object
Objects are the instances of user-defined classes that can store both values and functions. They must be explicitly declared.
Example
Output:
Bike Model: Royal Enfield
This is an advanced topic of PHP, which we will discuss later in detail.
Special Types
PHP Resource
Resources are not the exact data type in PHP. Basically, these are used to store some function calls or references to external PHP resources. For example - a database call. It is an external resource.
This is an advanced topic of PHP, so we will discuss it later in detail with examples.
PHP Null
Null is a special data type that has only one value: NULL. There is a convention of writing it in capital letters as it is case sensitive.
The special type of data type NULL defined a variable with no value.
Example
Next TopicPHP Operators