Skip to content

PHP Tutorial Data Types

Booleans

Lesson 38 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

A boolean has only two possible values: true or false. Booleans are the answer to a yes-or-no question, and they drive every decision in your code.

index.php
PHP
<?php
$isLoggedIn = true;
$hasPaid = false;

var_dump($isLoggedIn, $hasPaid);
Output
OUTPUT
bool(true)
bool(false)

Comparisons produce booleans

index.php
PHP
<?php
$age = 20;

var_dump($age >= 18);
var_dump($age === 30);
Output
OUTPUT
bool(true)
bool(false)

Printing a boolean

echo true prints 1, and echo false prints nothing at all. That surprises many beginners.

index.php
PHP
<?php
echo "[" . true . "]\n";
echo "[" . false . "]";
Output
OUTPUT
[1]
[]

To see the real value, use var_dump(), or write your own words.

index.php
PHP
<?php
$active = false;
echo $active ? "Active" : "Inactive";
Output
OUTPUT
Inactive

What counts as false?

When PHP needs a yes or no (for example in an if), it converts the value to a boolean. These values become false, and everything else becomes true:

  • false
  • 0 and 0.0
  • "" (empty string) and "0"
  • [] (empty array)
  • null
index.php
PHP
<?php
var_dump((bool) "hello");
var_dump((bool) "0");
var_dump((bool) []);
var_dump((bool) "false");
Output
OUTPUT
bool(true)
bool(false)
bool(false)
bool(true)

Notice the last line: the text "false" is a non-empty string, so it is true.

warning
The string "false" is true
If a form or API sends the text "false", if ($value) treats it as true. Compare the text, or use filter_var($value, FILTER_VALIDATE_BOOLEAN).