What are the different data types in PHP?

The PHP manual lists ten primitive data types in three groups.

GroupTypeExample
Scalarstring“Hello PHP!”
Scalarinteger2567
Scalarfloat (double)1.5 or 134.153
Scalarbooleantrue or false
Compoundarray[1, 2, 3]
CompoundobjectAn instance of a class
CompoundcallableA function that can be called
CompounditerableAn array or an object that can be looped
SpecialNULLA variable with no value
SpecialresourceA 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
Interview Questions & Answers
How to check if a variable is empty in PHP?
Is PHP a case sensitive language?
What are the different data types in PHP?
How to define a Constant in PHP?
What is the difference between $var and $$var in PHP?
Which special characters are allowed in PHP variable names?
Can we print multiple variables in a single echo statement in PHP?