Variables are like containers for storing information. In PHP a variable is declared by prepending a dollar ($) to the variable name. Unlike other programming languages, PHP has no command for declaring a variable – the variable is created the moment you first assign a value to it.
A variable name must either begin with a letter or the underscore character but it cannot start with a number. Besides, a variable name can only contain alphanumeric characters and the underscore.
In the example below we are going to declare a variable to store the name of country of a famous football star.
$country = "Brazil";
Declaring a variable is a statement in PHP and so we have to terminate it with a semicolon.
Geoffrey is an experienced software developer and open source evangelist. When not coding he writes and talks about current technology trends, small business tips and developer productivity hacks. He is no coffee addict.
How to Become Efficient With a 5 Step Web Development Life Cycle
How to Become a Professional Android Developer in 6 Simple Steps
Interview with Rob Percival – How To Land Your First Junior Developer Job
How To Become a Professional iOS Developer
How to Browser the Internet Anonymously Using the Tor Browser
Is PHP Programming Obsolete?