Variables in PHP

In this tutorial we will learn Variables in PHP. Variables are use to store data like to store string or number for example min_age=18. Value of variable can be changed several times through out the code. It is so easy to define variable in PHP just write $sign and then variable name like this $min_age=18. You do not even need to mention data type of variable. Because PHP will automatically choose correct data type of variable according to value stored in variable.

Variables in PHP

Basic Things to keep in mind while creating Variables in PHP

  • All variables in PHP start with a $ sign, followed by the name of the variable.
  • A variable name must start with a letter or the underscore character _.
  • Variable name cannot start with a number.
  • Variable name in PHP can only contain alpha-numeric characters and underscores (A-z, 0-9, and _).
  • Variable name cannot contain spaces.

There are some rules which you should follow while defining and variable name. To initialize a variable you just need assignment operator (=) then write value of variable for example $min_age=18 or $name="Mohit".

Now we will check this basic example to understand Variables in PHP.


Note! Please note I am using dot (.) symbol in above example in echo to concatenate strings.

Share this tutorial with your friends on your social Media..

Variables in PHP Variables in PHP Variables in PHP Variables in PHP

Now You Can Follow All These Tutorials on Your Android Mobile Just Download This App.