Variables are "containers" for storing information.
In PHP, a variable starts with the $ sign, followed by the name of the variable:
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
echo $txt;
echo "<br>";
echo $x;
echo "<br>";
echo $y;
?>
Note: When you assign a text value to a variable, put quotes around the value.
Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it.
A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).
Rules for PHP variables:
Remember that PHP variable names are case-sensitive!
The PHP echo statement is often used to output data to the screen.
<?php
$txt = "hello world";
echo "$txt !";
?>
The following example will output the sum of two variables:
<?php
$x = 5;
$y = 4;
echo $x + $y;
?>