Variable is an identifier used for storing the values like text strings, numbers or arrays which is stored in the system’s memory and can be retrieved any time during the program. After declaring the value of variable, it can be used unlimited time during the program.
All variables in PHP begins with a $ symbol. Here is an example of declaring the correct way of variable:
$var_name = value;
Remember, always use the $ symbol at the beginning of the variable, otherwise it will not work. For more clarity, lets see an example of Hello World:
The output will be like - Hello World.
In terms of value declaration, PHP is an exceptional language that does not need to be declared before adding a value to it. PHP automatically converts the variable to the correct data type, depending on its value. For example:
2. $string = “Hello Users”;
3. print (“Welcome to Roseindia, I want to greet $string”);
4. print (“<p>”);
5. $string = “Bye Bye!”;
6. print (“OK meet you soon, $string”);
3.4.1 Rules for Declaring Variables
Variable names are case sensitive and can be used carefully. Besides, string and numbers, variables can also be in some other things like objects, arrays, Booleans, etc.
Posted on: July 10, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles