Skip to content
Justice Tech School

Variables

A variable starts with $ and is created when you assign to it, with no type declaration. Names are case sensitive. Use double quotes to insert variables into text, and single quotes for plain text. define() or const make constants.

Example
$name = "Ada";
$age = 21;
$price = 19.99;
$active = true;
echo "Name: $name, age $age\n";
echo 'No $interpolation here\n';
const MAX = 100;
echo MAX, "\n";
$x = 5; $y = 10;
echo $x + $y, "\n";

Result

Name: Ada, age 21
No $interpolation here\n100
15

Exercise

Which symbol starts a variable name?

name = "Ada";

Quiz Test

Which quotes insert variables into text?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.