Getting Started with PHP – Part 5 (PHP DataTypes)

Guest Posts Paolo Nikko Nuñal

In our last tutorial we discussed about PHP variables, in this tutorial we are going to learn data types and how you can manipulate them in your code.

There are seven data-types in PHP namely:

  • String

  • Integer

  • Floating point numbers

  • Boolean

  • Array

  • Object

  • NULL


PHP strings are a sequence of characters and are placed inside single or double quotes.

   $txt = "Hello World";
   $txt2 = 'The quick brown fox jumps over the lazy dog";

   echo $txt."<br>";
   echo $txt2;


In PHP, an integer is a whole number or in other words a number that doesn't have any decimals.

   $num1 = 23;
   $num2 = 24;

Floating Point Numbers

In PHP, a floating point is a number with decimals.

   $num1 = 2.34;
   $num2 = 8E-5;


In PHP, a boolean can either be TRUE or FALSE

   $stmt = true;
   $stmt2 = false;


Arrays can store multiple values in  a single variable. You can check out our other pages that deals more about ARRAYS and functions.

   $array = array ("mango","carrot","onions","tomatoes");
   echo var_dump($array);


PHP variables can hold objects. But to declare an object you need to first imply what type of object you are creating.

  $person = new Person();

Null Value

In PHP you can specify variables as null. Null is the only possible value of the data type null. Values can be emptied and set with a null.

  $x= 23;
  $x = null;