Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources


One of the most important parts of learning any programming language is to understand what are the available data types, and how data is stored, accessed and manipulated in that language. In PHP, different types of data can be stored using variables. PHP supports the following data types:

Data TypesDescription
StringsUsed to store text or sequence of characters like "This is a string".
IntegersNon-decimal number between -2,147,483,648 and 2,147,483,647.
Doubles Floating-point numbers like 10.5.
BooleanTwo possible values either true or false.
Arrayare named and indexed collections of other values.
Objectare instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
NULLis a special type that only has one value: NULL.
Resourceare special variables that hold references to resources external to PHP (such as database connections).

PHP Strings

Strings are one of the most common data types in PHP. It is used for storing text. A string can be any text inside single or double quotes. Please consider the example below:

<?php
$x = "HELLO WORLD!.";
$y = 'Hello World!.';

echo $x."\n";
echo $y;
?>

The output of the above code will be:

HELLO WORLD!.
Hello World!.

PHP Doubles

Doubles are the floating point numbers like 10.5. By default, Doubles print with the minimum number of decimal places required. Consider the below example:

<?php
$x = 10.555500;
$y = 25.34450000;
$z = $x + $y;

echo "$x + $y = $z";
?>

The output of the above code will be:

10.5555 + 25.3445 = 35.9

PHP Booleans

Booleans have two possible values either true or false. It is generally used for condition testing. Consider the below example:

<?php
$x = 10.555500;
$y = 25.34450000;
$z = $x + $y;

echo "$x + $y = $z";
?>

The output of the above code will be:

10.5555 + 25.3445 = 35.9

5