Friday, July 30, 2010

PHP Variables

• As u know variables r used 4 storing values like text strings, numbers or arrays and when a variable is declared, it can b used over and over again in the script.

• But how variables r declared in php script???[:o]

• All variables in php start wid $ sign symbol.
e.g. $var_name = value;

• Let us take some php code:

• PHP is a loosely typed language:
o In PHP, a variable does not need to be declared before adding a value to it.
o In the example above, you see that you do not have to tell PHP which data type the variable is.
o PHP automatically converts the variable to the correct data type, depending on its value.[:)]
o In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it.
o In PHP, the variable is declared automatically when you use it.

• Naming Rules for variables:
o A variable name must start with a letter or an underscore "_".
o A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ ).
o A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)

2 comments:

  1. well...i dont know much about php.....
    but in ur words....it seems to b very interesting.....
    n
    seriously...it's vry smooth n easy-going...
    bravooo!!!....the worthy efforts...
    :)

    ReplyDelete