A variable is a memory space or location that is meant to hold data. Variables are essential in programming because they are essentially the source of all operations a program code can perform.
If you wish to add two or more numbers, store a name and perform a retrieval. The outputs or inputs of this operation need to be placed somewhere in the computer’s memory.
In PHP, there are some governing rules to name and declare variables. However, doing this in PHP is quite easier than in languages like Java and C where you must also state the type of data to be stored.
It is widely known that PHP is a loosely typed language. This simply means that you don’t need to state the data type of the variable.
Below are some rules that govern how to name your variables in PHP.
_) or any letter, but not with a number or a special character.
//right variable names $manure = "growth supplements"; $_dressSize = 4; $hymn123 = "my young days"; //wrong names hey ="not so"; //doesn't have $ $123buckle ="still wrong"; //cannot follow $ with a number $@gmail ="ooops error!"; //cannot use @
//I wish to save my favorite quote $myFavQoute = "live let's live"; //camelCased and reflects its data
View all Courses