Saturday, December 10, 2011

PHP Variables

As many programming language define, variables is a symbolic representation of a value.

A valid variable name:
  1. Starts with a dollar sign ($)
  2. Followed by either a letter or underscore
  3. Can contain numbers, numbers, underscores, dashes (hyphen)
  4. Case-Sensitive
  5. No spaces
Variable name examples:
Avoid these variable format:
$_itemPrice; //PHP defined variables, $_POST, $_GET etc.
$__itemPrice; //double/triple/four underscore can be confusing
Lets take Variables in action:
        <title>PHP Variables</title>
        $price1 = 25;
        echo $price1 . '<br />';
        $products = 'product lowercase';
        $Products = 'product uppercase';
        echo $products . '<br />';
        echo $Products . '<br />';
        $price1 = 500;
        echo $price1;

No comments:

Post a Comment