PHP variables and data types

Beginner  Nov 3, 2026

Store values in variables and learn the five types you will use every day.

PHP variables and data types
The steps of this tutorial at a glance.
The steps of this tutorial at a glance.

Variables

A PHP variable starts with $ and has no declared type. PHP decides the type from the value.

<?php
$name  = 'Ali';        // string
$age   = 30;           // integer
$price = 19.99;        // float
$ok    = true;         // boolean
$list  = [1, 2, 3];    // array
How the code in this section fits into the page.
How the code in this section fits into the page.

Check a type

var_dump($age);        // int(30)
echo gettype($price);  // double

Joining text

Use . to join strings, or put variables inside double quotes:

echo 'Hello ' . $name . '!';
echo "Hello $name, you are $age years old.";

Common mistakes

  • '$name' in single quotes prints the text $name, not the value.
  • "5" + 3 gives 8, because PHP converts the string. Add declare(strict_types=1); at the top of a file to get errors instead of silent conversion in function calls.
  • Variable names are case-sensitive: $Name and $name are different.
The main points of this section.
The main points of this section.

Try it

Make variables for your name, age and city, then print one sentence that uses all three.

More tutorials