Data type specifies which type of value a variable has. During PHP program variables are used to store informations.
PHP supports following data types to construct our variables –
1. PHP Integers – A PHP Integer data type is a whole number (non-decimal numbers).
To check the datatype and value of a variable, a function var_dump() is used.
<?php $x = 4296; var_dump($x); ?>
2. PHP Floats – A float is a decimal point number or an exponential form number.
For example –
33.303, 0.93993, -9390240.93493 are floating point numbers.
<?php $x = 93933.39; Var_dump($x); ?>
3.PHP Boolean – Boolean data type is any data type having only true or false value, yes or no, on or off (0 or 1).
For example
$x = true;
$y = false;
4. PHP Array – An array is a container which holds multiple values of a single type.
For example –
$subjects = array(“English”, “Hindi”, “Math”);
5. PHP Object – An object is an instance of a class which can be containing variables, functions and data structures.
An object data type variable stores data and information.
$var1 = NULL; $var2 = "";
Both $var1 and $var2 are two different values containing variables. $var1 has null value whereas $var2 has to assigned some values.
6. PHP resources – Resource is a special type of datatype which does not store any actual data but stores reference to some external source of data/information.
For example-
A very common example of it is Database call.
<?php Class Car{ Function car(){ $this->model = “BMW”; } } //Create an object $newcar = new Car(); //object properties Echo $newcar->model; ?>
7. PHP NULL – PHP Null values is used to represent only empty values. Any variable of NULL type is without any data. And its only value is NULL.
Whenever you create a variable like $car with no value in it. It is automatically assigned NULL