Using variables in PHP is done in every single script, and is extremely basic PHP knowledge. If you have experience in any other programming languages, you’ll know that all languages use variables. Variables are basically peices of code that hold information.
I’ll give you a basic, real life example of variable use. If you remember your mathematics class, you’ll probably remember that in algebra, you used letters that would represent a number. For example, if I said “n = 1”, then every time you seen the letter “n” in a mathematical equation, you’d see it as “1”. This is a perfect example of how variables are seen by the PHP parser. Look at the example below.
<?php
$variable = "hello";
?>
As you can imagine, the variable “$variable” is now going to be translated into “hello” by the PHP parser every time it is read. It’s relatively simple. Notice how I used the PHP syntax (tags, semi-colons) in this as well. Remember, they are required! In the next tutorial (“PHP Echo“), we’re going to learn how to put all this knowledge together and output things onto the screen with PHP using the echo() function.