HOME HTML EDITOR C JAVA PHP

PHP Data Types

Variables can store data of different types, and different data types can do different things. PHP supports the following data types:

1. String

A string is a sequence of characters, like "Hello world!". A string can be any text inside quotes. You can use single or double quotes:

<?php
  $x = "Hello world!";
  $y = 'Hello world!';

  echo $x;
  echo "<br>";
  echo $y;
?>

2. Integer

An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.

<?php
  $x = 5985;
  var_dump($x);
?>

3. Float (floating point numbers)

A float is a number with a decimal point or a number in exponential form.

<?php
  $x = 10.365;
  var_dump($x);
?>

4. Boolean

A Boolean represents two possible states: TRUE or FALSE. Booleans are often used in conditional testing.

<?php
  $x = true;
  $y = false;
?>

5. Array

An array stores multiple values in one single variable.

<?php
  $cars = array("Volvo", "BMW", "Toyota");
  var_dump($cars);
?>

6. PHP NULL Value

Null is a special data type which can have only one value: NULL. A variable of data type NULL is a variable that has no value assigned to it.

<?php
  $x = "Hello World!";
  $x = null;
  var_dump($x);
?>
Pro Tip: Use the var_dump() function to see the data type and the value of any variable. It is extremely helpful for debugging!