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:
<?php $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.
<?php $num1 = 23; $num2 = 24; ?>
Floating Point Numbers
In PHP, a floating point is a number with decimals.
<?php $num1 = 2.34; $num2 = 8E-5; ?>
In PHP, a boolean can either be TRUE or FALSE
<?php $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.
<?php $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.
<?php $person = new Person(); ?>
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.
<?php $x= 23; $x = null; ?>