Sunday, 13 January 2013

How to use variables in PHP?

Now you are very much familiar with displaying any sample text in PHP using syntax, today we would learn how php variables play an important roles in programming.

When we say “variables”, what instantly come to your mind?

Anything whose value keeps changing.

Variable in PHP are declared using “$”. I would elaborate it with example

$var_name = "value";

The above syntax is explained as “$var_name” is the name of the variable and “value” will be the value which we wish to assign to this variable.

This would be better understood with following example:

$my_name = "";
echo $my_name;

As you can see that we can assign any string to the variable and for displaying the value we can use the “echo” command

No comments:

Post a Comment