Variables in PHP. Chapter 2 of Getting started with Basics of PHP

No Comments

In previous chapter we learned about basics of PHP including php syntax, commenting in php and how to output in php using echo. In this chapter we will learn all about PHP variables.

What does Variable stands in PHP ? For a new learner this would be the most important thing to be learned. Variables are “containers” for storing information.

In Simple terms, if you want to store any information and retrieve it later, you need to store that information in a VARIABLE. says,

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.


[notification type=”notify” title=”To be Noted”]$this is a special variable that can’t be assigned.[/notification]


If we want to make a variable to store Names of students of class a good variable would be $Name instead of $blahblahblah. Again I would like to recall variables are CASE SENSITIVE. $footballmatch and $Footballmatch are different.


$name = 'David';

$scoreNumberValue = 48;

$scoreStringValue = '48';

$name contains David,

we can use echo command to display David  

echo $name;

Now we also have used two more variables to store data,
and same data is stored in both that is 48, but there is a small difference. 

Case 1

$scoreNumberValue = 48;

this variable stores number 48 and
this can be used for mathematical calculations.
Data stored is without quotes.

Case 2 

$scoreStringValue = '48';

this variable stores data in quotes,
so php considers this as more of a string, so can not be used for
mathematical calculations

Hmm, that was easy, I hope you all learned something good out of this tutorial. Well this is beginning of something very good. The next chapter would cover Arithmetic Operators in PHP i.e how to do addition, subtraction, division, multiplication in php.

If you have any questions feel free to drop them in comments.

A website developer, loves #wordpress #drupal #php. Love posting about wordpress, php, bootstrap and SEO. Also provide online/offline training on wordpress, drupal, php and SEO. I am available on Twitter @ anibabbar , Skype @anibabbar , gmail @anibabbar !! facebook

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

Fields marked with an * are required
July 2019
« Sep    

More from our blog

See all posts
No Comments