PHP Variable lessons and tutorials web development

PHP Variable

In the last PHP Lesson we learned how to echo out a line of text in a browser in this lesson we will learn about a php variable. A variable in php stores information. In the example below we see that a variable starts with a $ sign and is followed by text.

<?php $name ="My name is Max" ?>

In the example above we see a very simple php variable structure. This code in itself will show nothing in a browser because we have not echoed anything so in order for it to show in the browser we would have to echo it out like in the example below.

$name ="My name is Max";
echo $name; ?>

Try it for yourself in the PHP code pad below provided by . Just highlight all the text that you see in the box and click backspace to put in your PHP Variable.

PHP Variable

Only cool people share!

Make sure that you start with the PHP open and close tags, so you can leave the red PHP if you do not want to type them out again. This is important for a PHP Variable.

<–?php ?–> Minus the — signs, of course.

Also remember that in order to see your code in action, you must click the “Run” button.

PHP Variable

Simple right? Ok well let’s include some line breaks like we learned before. A line break is a HTML code, and it tells the browser that we want to start a new line. We learned this in our previous PHP lesson.

So let’s try this code in our PHP fiddle.

$variable ="Hello my name is Max I work at<br/> is the #1 Web Development company in the world<br/>
Contact them today if you are serious about having a top notch website";
echo $variable;


Another great thing about PHP is that you can do math with it. Check out this code below.

$two = 2;

echo $two + $three;

PHP Variable lessons and tutorials web development was last modified: August 18th, 2022 by Maximus Mccullough
PHP Web Development

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.