Thursday, February 16, 2012

PHP - Variables

What do you know about PHP variables ?
A variable is a means of storing a value,such as text string "Hello World" or the integer value.
In PHP you define a variable with the following form :
    PHP Variable declaration:
  • $variable_name = "value";
    Example:
  • $myString = "Hello";
Note:
Keep it on your mind,
If you forget that dollar sign at the beginning, it will not work. this is a common mistake for new programmer!





  • You also remember that, variable names are case-sensitive. So use the exact same capitalization when you using a variable.
  • The variables $a_market and $A_market are different variable in PHP's eyes.



  • PHP Variable Naming Conventions :
    There are some rules that you need to follow when choosing a name for a variables.
    • PHP Variables must be start a letter or underscore " _ ".
    • Variables may only be comprised of alpha-numeric characters and underscores. a-z,A-Z,0-9 or _.
    • Variables with more than one word should be separated with underscores. [ $my_variable ]
    • Variables with more than one word can also be distinguished with capitalization.[$myVariable]

    No comments:

    Post a Comment