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

PHP Variable lessons and tutorials web development

Contents

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.

<?php
$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.

<br/>

So lets try this code in out php fiddle.

<?php
$variable ="Hello my name is Max I work at A1WebsitePro.com<br/>
A1WebsitePro.com 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.

<?php
$two ="2";
$three ="3";

echo $two + $three;
?>

See it in action by putting the code.

PHP FIDDLE


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: May 11th, 2015 by Maximus Mccullough

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

Tips

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.