A little knowledge of programming, drafting or Algebra can make it easy to understand the basics of variables. In order to understand variables, a long time practice is required. Here is a refreshment course for you.
A specific way, which helps us in saving a string text value like, “Welcome here!” or an integer like 3, is known as Variable. So, it is helpful to you in your programming. There is no need to write the value again and again in the program. You have to write the variable only. The format of declaring a variable is given here:
If you are a beginner, then you have to know that $ sign is essential in PHP. Without this sign, the program will not run.
Reminder: – It is very important to write the accurate name of the variable. If you written $b_number, then $B_number will be thought another name in PHP.
An example of Variable in PHP
It is good if you want to practice what you have learnt up till now. For this purpose, you have to write the name of a variable. Now, you have to make it equivalent to the required value. Here is the right of making that program:
PHP Variable Code
$welcome = "Welcome here!”;
$b_number = 5;
$newnumber = 9;
It is important to know that in PHP, variables are not declared before their start.
Rules of defining PHP Variable name:
When you select the name of your variable, you have to be careful about some rules.
1- The initial word of PHP variables ought to be a letter, otherwise an underscore.
2- There can only be characters of alphabets, underscores and numbers.
3- If a variable has two or more than two words then it should be disconnected with “_” like $new_variable.
4- The variables which have many words, they can also get detached by capitalization like $newVariable.