Thursday, March 10, 2011

Variables in PHP

variables are used for storing a value,like text strings,numbers or arrays.
when a variable is declared,it can be used over and over again in your script.  
All variables in PHP with a $sign symbol.
The correct way of declaring a variable in PHP:
 $var_name=value; 

New PHP programmers often forget the $sign at the beginning of the variable.In that case it will no work.
Let's try creating a variable containing a string,and a variable containing a number:

    <?php
     $txt="Hello World!";
      
     $x=16;

     ?>

PHP is a Loosely Typed Language. 
In PHP,a variable does not need to be declared before adding a value to it.
In the exmple above,you see that you do not have to tell PHP which data  type the variable is. 
PHP automatically converts the variable to the correct data type,depending on it's value.
In a strongly typed programming language,you have to declare (define) the type and name of  the variable before use it.
In PHP,the variables is declared automatically when you use it.      

6 comments:

  1. what is the meaning of Loosely typed language, i didn't understand that?Merge Statemet

    ReplyDelete
  2. very nice and informative
    good work

    ReplyDelete
  3. Thank you for informative article, guys! For your readers who haven`t decide yet which way is better to learn php we`ve just posted an article "PHP Training:Online vs. Classroom" on our blog: http://www.learncomputer.com/php-training-online-vs-classroom/

    ReplyDelete
  4. Php Language used for server site Prpgramming Language. if u have Some Programming Skil Some C Language, Java Skill and Perl than u Perfect Learn php.

    ReplyDelete

  5. I actually enjoyed reading through this posting.Many thanks.



    PHP Course in Chennai

    ReplyDelete