Simple PHP Tutorials - Lesson 2: Variables

Welcome to the second installment of Simple PHP Tutorials. Today we will be discussing variables. is a symbolic representation used to denote a quantity or expression.

Okay, so let’s look at this in terms of a PHP block:

<?

$myVariable = “Hello World”;

echo $myVarible;

?>

Okay, let’s look at the lines here. The first line is the declaration of the variable $myVariable. In PHP, all variables start with the ‘$’ sign. This line sets the variable $myVariable equal to the text “Hello World” so we can use it later.

The next line uses the echo function which, as we learned in the first lesson, displays text to the screen.

Variables can be used with many types of data. For example we could have set the variable $myVariable equal to the number 1. Then we could do the following:

<?

$myVariable = 1;

$myVariable = $myVariable + 1;

?>

Okay, so here we’ve set $myVariable equal to one and then added on to it and put the result back into $myVariable.

Well, that concludes this addition of Simple PHP Tutorials. Join us next time when we will discuss if statements.

Leave a Reply