7/17/25, 4:48 PM PHP Data Types
Tutorials Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
PHP Data Types
❮ Previous Next ❯
PHP Data Types
Variables can store data of different types, and different data types can do different things.
PHP supports the following data types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
Resource
Getting the Data Type
You can get the data type of any object by using the var_dump() function.
Example Get your own PHP Server
The var_dump() function returns the data type and the value:
https://www.w3schools.com/php/php_datatypes.asp 1/12
7/17/25, 4:48 PM PHP Data Types
$x = Tutorials
5;
var_dump($x);
Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Try it Yourself »
PHP String
A string is a sequence of characters, like "Hello world!".
A string can be any text inside quotes. You can use single or double quotes:
Example
$x = "Hello world!";
$y = 'Hello world!';
var_dump($x);
echo "<br>";
var_dump($y);
Try it Yourself »
PHP Integer
An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Rules for integers:
An integer must have at least one digit
An integer must not have a decimal point
An integer can be either positive or negative
Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or
binary (base 2) notation
https://www.w3schools.com/php/php_datatypes.asp 2/12
7/17/25, 4:48 PM PHP Data Types
In the following example $x is an integer. The PHP var_dump() function returns the data type
and value:Tutorials Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Example
$x = 5985;
var_dump($x);
Try it Yourself »
ADVERTISEMENT
PHP Float
A float (floating point number) is a number with a decimal point or a number in exponential form.
In the following example $x is a float. The PHP var_dump() function returns the data type and
value:
Example
$x = 10.365;
var_dump($x);
Try it Yourself »
PHP Boolean
https://www.w3schools.com/php/php_datatypes.asp 3/12
7/17/25, 4:48 PM PHP Data Types
A Boolean represents two possible states: TRUE or FALSE.
Tutorials Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Example
$x = true;
var_dump($x);
Try it Yourself »
Booleans are often used in conditional testing.
You will learn more about conditional testing in the PHP If...Else chapter.
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:
Example
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
Try it Yourself »
You will learn a lot more about arrays in later chapters of this tutorial.
PHP Object
Classes and objects are the two main aspects of object-oriented programming.
https://www.w3schools.com/php/php_datatypes.asp 4/12
7/17/25, 4:48 PM PHP Data Types
A class is a template for objects, and an object is an instance of a class.
Tutorials Exercises Services Get Certified
When the individual objects are created, they inherit all the properties and behaviors from the class,
HTML
but eachCSS JAVASCRIPT
object will SQL forPYTHON
have different values the properties. JAVA PHP HOW TO W3.CSS C
Let's assume we have a class named Car that can have properties like model, color, etc. We can
define variables like $model , $color , and so on, to hold the values of these properties.
When the individual objects (Volvo, BMW, Toyota, etc.) are created, they inherit all the properties and
behaviors from the class, but each object will have different values for the properties.
If you create a __construct() function, PHP will automatically call this function when you create
an object from a class.
Example
class Car {
public $color;
public $model;
public function __construct($color, $model) {
$this->color = $color;
$this->model = $model;
}
public function message() {
return "My car is a " . $this->color . " " . $this->model . "!";
}
}
$myCar = new Car("red", "Volvo");
var_dump($myCar);
Try it Yourself »
Do not worry if you do not understand the PHP Object syntax, you will learn more about that in the
PHP Classes/Objects chapter.
PHP NULL Value
https://www.w3schools.com/php/php_datatypes.asp 5/12
7/17/25, 4:48 PM PHP Data Types
Null is a special data type which can have only one value: NULL.
Tutorials Exercises Services Get Certified
A variable of data type NULL is a variable that has no value assigned to it.
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Tip: If a variable is created without a value, it is automatically assigned a value of NULL.
Variables can also be emptied by setting the value to NULL:
Example
$x = "Hello world!";
$x = null;
var_dump($x);
Try it Yourself »
Change Data Type
If you assign an integer value to a variable, the type will automatically be an integer.
If you assign a string to the same variable, the type will change to a string:
Example
$x = 5;
var_dump($x);
$x = "Hello";
var_dump($x);
Try it Yourself »
If you want to change the data type of an existing variable, but not by changing the value, you can
use casting.
https://www.w3schools.com/php/php_datatypes.asp 6/12
7/17/25, 4:48 PM PHP Data Types
Casting allows you to change data type on variables:
Tutorials Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Example
$x = 5;
$x = (string) $x;
var_dump($x);
Try it Yourself »
You will learn more about casting in the PHP Casting Chapter.
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.
A common example of using the resource data type is a database call.
We will not talk about the resource type here, since it is an advanced topic.
?
Exercise
What data type is the $x variable below:
$x = true;
Integer
Boolean
Float
String
https://www.w3schools.com/php/php_datatypes.asp 7/12
7/17/25, 4:48 PM PHP Data Types
Tutorials Exercises Services
Submit Answer »
Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
❮ Previous Next ❯
ADVERTISEMENT
https://www.w3schools.com/php/php_datatypes.asp 8/12
7/17/25, 4:48 PM PHP Data Types
Tutorials Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
COLOR PICKER
ADVERTISEMENT
https://www.w3schools.com/php/php_datatypes.asp 9/12
7/17/25, 4:48 PM PHP Data Types
Tutorials Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
ADVERTISEMENT
ADVERTISEMENT
https://www.w3schools.com/php/php_datatypes.asp 10/12
7/17/25, 4:48 PM PHP Data Types
Tutorials Exercises Services Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
PLUS SPACES
GET CERTIFIED FOR TEACHERS
FOR BUSINESS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
https://www.w3schools.com/php/php_datatypes.asp 11/12
7/17/25, 4:48 PM PHP Data Types
Python Reference
Tutorials W3.CSS Reference
Exercises
Bootstrap Reference
Services Get Certified
PHP Reference
HTML
CSS HTML ColorsSQL
JAVASCRIPT PYTHON JAVA PHP HOW TO W3.CSS C
Java Reference
Angular Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and
privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.
https://www.w3schools.com/php/php_datatypes.asp 12/12