PHP Data Types

A data type refers to, the type of data/details a variable can store.

PHP has totally eight data types. They are separated  as three major types. They are Scalar , Compound and special types. Below we listed out all the data types.

Scalar Types:

  • Boolean
  • Integer
  • String
  • Float

Compound Types:

  • Object
  • Array

Special Types:

  • NULL
  • Resources

DATA-TYPES

Note: var_dump() will return data type and value of the variable.
Integer:

We can specify integers in three formats.

  • Decimal
  • Hexadecimal
  • Octal
<?php
$a = 345;
$b = -234;
$c = 0x8C;
$d = 047;
var_dump($a);
echo "<br />";
var_dump($b);
echo "<br />";
var_dump($c);
echo "<br />";
var_dump($d);
?>

Output:

int(345)
int(-234)
int(140)
int(39)
 Float :

As we already know Float is a number with decimal point.

<?php
$a = "11.43";
var_dump($a);
$b = "23.5e2";
var_dump($b);
$c = "11e-3";
var_dump($c);
?>

Output:
float(11.43)
float(2350)
float(11.0E-3)
PHP Boolean

The data type Boolean either TRUE or FALSE

<?php
$a = true;
$b = false;
?>
PHP Array

Array is used to store multiple data/value in a single variable.

<?php
$student_role_no = array("12789","12790","12791");
?>
PHP Objects

In PHP an object is used to stores a data/value and information, how to process the data or we can say objects are user define the data type. We will learn more about this in Object oriented program page.

NULL

In PHP NULL is special data type.

Usually we will use this data type to check the variable data is present or empty.  It was assigned as a special constant named as “NULL”.

<?php
$a = "test";
$a = NULL;
?>

Note:Here NULL predefined constant data. So we no need to place it under singe(') or double ("") quotes. If we use unset()function for a variable  its value will get change as NULL.