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.
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.
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.
<?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.
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.
I hope you enjoyed the article. If I was able to help you please consider a tip for the content.
One Time Tip