A variable is the result of a number, string, or function that is stored in a program or in varying amounts.
Once a variable is set, we can use it repeatedly in the script.
All the variables in PHP start with the $ symbol.
The correct way to set variables in PHP is:
$var _name = value;
Beginners of PHP tend to forget the $ symbol in front of the variable. If you do that, the variable will be invalid.
Here we create a variable that has a string, and a variable that holds a value:
<?php
$txt = "Hello world!";
$number = 16;
?>
PHP is a loosely typed language (loosely Typed Language)
In PHP, you do not need to declare a variable before you use it.
In the example above, you see that you do not have to declare the data type of the variable to PHP.
Depending on how the variable is set, PHP automatically converts the variable to the correct data type.
In a strongly typed programming language, you must declare the type and name of the variable before using it.
In PHP, variables are declared automatically when they are used.
Naming rules for variables
Variable names must begin with a letter or underscore "_".
Variable names can only contain alphanumeric characters and underscores.
Variable names cannot contain spaces.
If a variable name consists of more than one word, you should use an underscore to delimit it (such as $my _string), or start with an uppercase letter (such as a $myString).