-
Basic PHP Tutorial - 2
In this tutorial, we will be covering variables.
What is a variable?
A variable is used to store data so it can be used at any time. It can also be overwritten at any time. Variables in PHP are easier than most other languages as you do not need to define the type. All you need to do is put a '$' before the word and an equals with the data afterwards.
Example :
If you wanted to store the word "Hello" in a variable, it would look like this :
PHP Code:
<?php
$var="Hello";
?>
With this new variable we can now print it.
PHP Code:
<?php
echo $var;
?>
Maths
We can even do maths with variables. For example :
PHP Code:
<?php
$x = 5;
$y = 10;
$z = $x+$y;
echo $z;
?>
This would echo 15 as 5 + 10 is 15.