Data Types in php – PHP Lessons

elephant_phpHere we come to the data types in PHP. Currently PHP supports 8 types of data types.

In this tutorial we consider only four:
PHP is a language with dynamic typing. I will explain a little – in the strongly typed language when we create a variable we immediately say what kind of data will be stored there. If we were declare that there will be a number then an attempt to put there something else will result in an error. In strongly typed languages ​​we cannot afford to use a variable of any data type without declaring it. PHP itself is trying to determine what kind of data type is stored in variable and usually he does it correctly.


Simple data type denotes the true value – is TRUE or FALSE – lie. TRUE and FALSE are case-insensitive. When we give some data to the server it does not have an idea what is true or false (TRUE or FALSE) and so these data are converted or reduced to a line. If we write the following code:

$user_name = true;
echo $user_name; // ?

What will display browser? In this case the data is converted to a string and a value of TRUE is reduced to a string. TRUE in the string version is “1”. And the browser will print one (1). The question is – what will the value FALSE? An empty string!


It’s all positive and negative whole numbers.


This is a floating point number (real). For example:

$float = 1.234;
$float = 1.2e3;
$float = 7E-10;


In PHP for the most parts we are working with strings. As we have seen you can enter put a string value in single quotes or double. In the double quotes we can substitute the values ​​of variables. For example:

$user_name = 'Martin';
echo "Hello, $user_name";

It will print «Hello, Martin». Everything is quite simple. But that’s not all. Just inside the double quotes we can use special characters. PHP to understand that this is a special character and not just a symbol it is protected by a slash.

$user_name = 'Martin';
echo "Hello, \n$user_name";


Variable will return NULL if it was not defined or it was deleted.

Leave a Reply

Your email address will not be published. Required fields are marked *