Originally published on zero2php.dev — part of the Zero to PHP course. View this lesson on the original site.

Names and rules

Variables start with $ followed by a name: letters, numbers, underscore; cannot start with a digit.

Example

<?php

declare(strict_types=1);

$message = 'Hello';
$count = 3;
$message = 'Hello again';

Assignment and naming

Assignment uses =. PHP is dynamically typed: the same variable name can hold different types over time—still be intentional.

Choose meaningful names: $total beats $t once more than one value exists.

Exercise

Put 7 in $x, 5 in $y, assign their sum to $total, and echo $total so the printed value is 12.

From Zero to PHP — PHP foundations: environment, syntax, and values