PHP Data Types

PHP Data Types are used to define the type of data that is to be stored. PHP data types can be classified into 3 groups:

● Scalar Data Types:

  1. String
  2. Integer
  3. Float
  4. Boolean

 

● Compound Data Types:

  1. Array
  2. Object

 

● Special Data Types:

  1. NULL
  2. Resource

String:

A sequence of characters is called as string. A string should be written inside a single or double quote.

Integer:

All the non-decimal numbers between -2,147,483,648 and 2,147,483,647 are called as Integers.

Float:

Float represents all the decimal and exponential numbers.

Boolean:

The boolean data type can only take two values, either TRUE or FALSE.

Array:

Array is used to store multiple data of same data type in the name of a single variable.

Object:

An object defines how a data need to be processed.

NULL:

A NULL data types holds a NULL value.

Resource:

It is not an actual data type. It is used to store external references and resources.

 

Example:

<!DOCTYPE html>
<html>
<body>
 
<?php
 
$x = "Hello world!";
$y = 5000;
$z = 10.01;
$w = array("a","b","c");
$v = null;
 
var_dump($x);
var_dump($y);
var_dump($z);
var_dump($w);
var_dump($v);
 
?>
</body>
</html>
Please Share