PHP Data Types

PHP data types define the kind of data a variable can store. PHP is loosely typed, meaning you don’t need to declare the data type explicitly—it’s determined automatically.

Here are the main PHP data types:

  • Integer
  • Float
  • String
  • Boolean
  • Array
  • Object
  • Null


Integer:
Whole numbers (positive or negative), without decimals.

$x = 10;
$y = -25;

Float:
Numbers with decimal points or exponential form.

$pi = 3.14;
$exp = 1.2e3;

String:
A sequence of characters (text), enclosed in quotes.

$name = "John";
$message = 'Hello World';

Boolean:
Represents two values: true or false.

$isActive = true;
$isLoggedIn = false;

Array:
Stores multiple values in a single variable.

$colors = array("red", "green", "blue");

Object:
Instance of a class (used in OOP).

class Car {
    public $color;
}

$myCar = new Car();
$myCar->color = "red";

NULL:
Represents a variable with no value.

$x = null;