1 Star2 Stars3 Stars4 Stars5 Stars (13 votes, average: 5.00 out of 5)

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.

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂
$name ="My name is Max";
echo $name;

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

PHP Variable

Subscribe To My YouTube Channel:

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 lets include some line breaks like we learned before. A line break is an html code and it tells the browser that we want to start a new line. We learned this in our previous php lesson.


So lets try this code in out php fiddle.

$variable =&quot;Hello my name is Max I work at A1WebsitePro.com&lt;br/&gt;
A1WebsitePro.com is the #1 Web Development company in the world&lt;br/&gt;
Contact them today if you are serious about having a top notch website&quot;;

echo $variable;

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

$two =&quot;2&quot;;
$three =&quot;3&quot;;

echo $two + $three;

See it in action by putting the code.


If you want to say updated on more WordPress tutorials and more subscribe to my feed and we will email them to you as we post them.

Enter your email address:

Delivered by FeedBurner

PHP Variable lessons and tutorials web development was last modified: November 18th, 2020 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips


Cool People Share:
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.