Data Types

Every value in PHP has a type: a whole number, a decimal number, text, true/false, a list, an object, or nothing at all. Knowing the types — and how to check them — is the key to understanding how PHP behaves, especially when values are compared or combined.

The types at a glance

TypeHoldsExample
intWhole numbers42, -7, 1_000_000
floatNumbers with a fractional part3.14, 1.5e3
stringText (a sequence of bytes)"hello", 'world'
booltrue or falsetrue
arrayOrdered lists and key–value maps[1, 2, 3], ['a' => 1]
objectInstances of classesnew DateTime()
nullNo valuenull

The first four are called scalar types. There are also callable (something you can call, lesson 31), iterable, and resource (a handle to something outside PHP, such as an open file in older APIs).

Inspecting types

var_dump shows type and value; get_debug_type returns the type's name as a string:

PHP
<?php

$values = [42, 3.5, "text", true, null, [1, 2], new DateTimeImmutable('2026-01-01')];

foreach ($values as $v) {
    echo get_debug_type($v), "\n";
}
var_dump(1.0, "1", false);
Output
int
float
string
bool
null
array
DateTimeImmutable
float(1)
string(1) "1"
bool(false)

Note that 1.0 is a float even though it has no fractional part — the decimal point decides.

Checking types with is_* functions

PHP
<?php

$x = "123";

var_dump(is_string($x));
var_dump(is_int($x));
var_dump(is_numeric($x));      // a number or a numeric string
var_dump(is_numeric("12abc"));
var_dump(is_array([]), is_null(null), is_bool(0));
Output
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
bool(true)
bool(false)

is_numeric is useful for input: form values always arrive as strings, so "123" is a string that looks like a number.

Integers

On 64-bit systems (all modern ones), integers range from about −9.2 quintillion to +9.2 quintillion. Underscores improve readability, and you can write hexadecimal, octal and binary literals:

PHP
<?php

echo PHP_INT_MAX, "\n";
echo PHP_INT_SIZE, " bytes\n";
echo 1_000_000, "\n";
echo 0xFF, " ", 0o17, " ", 0b1010, "\n";

var_dump(PHP_INT_MAX + 1);   // too big: becomes a float
Output
9223372036854775807
8 bytes
1000000
255 15 10
float(9.223372036854776E+18)

When an integer calculation overflows, PHP silently switches to a float, which loses precision. That rarely matters, but it's good to know.

Floats

Floats are binary floating-point numbers with about 15–17 significant digits. Like in most languages, some decimal fractions can't be stored exactly:

PHP
<?php

$sum = 0.1 + 0.2;
echo $sum, "\n";
var_dump($sum);
var_dump($sum == 0.3);
var_dump(abs($sum - 0.3) < PHP_FLOAT_EPSILON);
Output
0.3
float(0.30000000000000004)
bool(false)
bool(true)

echo rounds floats for display, hiding the error that var_dump reveals. Never compare floats with == after calculations, and don't use floats for money — lesson 8 shows the alternatives.

Strings and booleans

Strings hold text of any length; lessons 16–20 are devoted to them. Booleans are true and false (case-insensitive, but write them in lower case). They're usually the result of a comparison:

PHP
<?php

$age = 20;
$isAdult = $age >= 18;
var_dump($isAdult);

echo "true prints as: [", true, "]\n";
echo "false prints as: [", false, "]\n";
Output
bool(true)
true prints as: [1]
false prints as: []

Echoing a boolean prints 1 for true and nothing at all for false — use var_dump or a conditional ($ok ? 'yes' : 'no') when you need to see it.

Arrays and objects

PHP's array is one flexible type that acts as a list, a dictionary, a stack or a queue. Objects are instances of classes. Both get whole sections of their own (lessons 21–26 and 33–43):

PHP
<?php

$colours = ["red", "green", "blue"];
$person = ["name" => "Ada", "born" => 1815];
$date = new DateTimeImmutable("2026-03-14");

echo $colours[1], "\n";
echo $person["name"], "\n";
echo $date->format("l"), "\n";
Output
green
Ada
Saturday

Null

null is the only value of the null type. A variable is null if it's been assigned null, or after unset(); functions that find nothing often return null.

Try it yourself

Add more values to the array and predict what get_debug_type will print for each.

Try it yourself · main.php
Edit the code, copy it into main.php, then run it with php main.php (PHP 8.5). How to install PHP
Output
int    numeric
float  numeric
string numeric
string not numeric
bool   not numeric
null   not numeric
array  not numeric