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:
$Products;
$salePrice;
$sale_price;
$item3;
$_itemName;
$__itemPrice;
Avoid these variable format:
$_itemPrice; //PHP defined variables, $_POST, $_GET etc.
$__itemPrice; //double/triple/four underscore can be confusing
Lets take Variables in action:
<html>
    <head>
        <title>PHP Variables</title>
    </head>
    <body>
        <?php
        $price1 = 25;
        echo $price1 . '<br />';
        $products = 'product lowercase';
        $Products = 'product uppercase';
        echo $products . '<br />';
        echo $Products . '<br />';
        $price1 = 500;
        echo $price1;
        ?>
    </body>
</html>

No comments:

Post a Comment