What are the different data types in PHP?
The PHP manual lists ten primitive data types in three groups.
| Group | Type | Example |
|---|---|---|
| Scalar | string | “Hello PHP!” |
| Scalar | integer | 2567 |
| Scalar | float (double) | 1.5 or 134.153 |
| Scalar | boolean | true or false |
| Compound | array | [1, 2, 3] |
| Compound | object | An instance of a class |
| Compound | callable | A function that can be called |
| Compound | iterable | An array or an object that can be looped |
| Special | NULL | A variable with no value |
| Special | resource | A reference to an outside thing, like an open file |
In PHP you do not write the type when you create a variable. PHP picks it from the value. You can check it with var_dump() or gettype(). Learn all of them with examples in PHP Data Types.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Variables |
| PHP Data Types |
| PHP Constants |
| PHP isset() Function |
| PHP empty() Function |
| PHP is_null() Function |
| Exercises & Assignments |
|---|
| Write a program to print “Hello PHP” using variable |
| Write a program to print a string using echo+variable. |
| Write a program to print two variables in single echo |