02
Feb
2011
2011
PHP Variables
Posted in: PHP
No Comments

What is PHP variables:
PHP variables are used to store and retrieve some data.
How to write PHP Variables
- All variables must start with a dollar sign $
- The name of the variable can consist of letters and numbers and special characters like underscore ‘_’, But must begin with a letter.
PHP variables are case sensitive $name is not the same as $NAME
Examples of PHP Variables
$sitename = '52webdesign.com'; // valid variable $4sitname = '52webdesign.com'; // invalid variable since it starts with a number $_4site = '52webdesign.com'; // valid variable since it starts with a special character under score.
More Examples of PHP Variables
$testvariable = 4 + 1; // Assigns a value of 5. $testvariable = 4 – 1; // Assigns a value of 3. $testvariable = 4 * 2; // Assigns a value of 8. $testvariable = 4 / 2; // Assigns a value of 2.
Another Examples of PHP Variables
<?php $a = 2; //we created a variable a and assigned it a value of 2 $b = 7; //we created a variable b and assigned it a value of 7 $c = $a * $b; //we multiply varaible a and b and store the value in c echo $c; //we print the content of variable c which is 14 ?>










