Data Types in PHP

Our world is full of objects that we can see, feel and interact with. The something, also in the software world we have different virtual materials and we need to deal with each type differently.

Boolean

Boolean data type has only two possible values: true and false.

Eg

$honest = true; $honest = false;

Number

Number is an integer value used to create some numerical calculation.

Eg

$n = 0; $n = 9;

String

String or text values stored in a PHP variable are type of String.

Eg

$honest = “I am honest!”; $honest = “1234567890”;

Eg

 <?php $male = [“wife”, “car”, “huis”, “dog”, “1000000”]; echo $male[2]; ?>

Objects

Objects are a blueprint of real life object and they may contain properties and behaviours.

Eg

 <?php /*The class description here*/ Class Animal{ var $name; function setAnimal($type){ $this -> name = $type; } function getAnimal(){ return “Animal type: “. $this>name . “.”;} } /*Instantiating objects*/ $test = new Animal; $test->setAnimal(“Dog”); echo $test -> getAnimal() ?>

Data types in PHP are less strict than in other high level programming languages. Reserved keywords which are used to define variables in a PHP program. PHP is object oriented server-side web programming language.