Php variables

      No Comments on Php variables

Php variables declaration

A Php variables begin with $ dollar sign followed by the variable name. The rules are same as that of C++

  • Variable name can begin with a letter or an underscore ‘_’ .
  • Variable name can be combination of letter, digits, or underscores.
  • Some valid examples are-
  • Variable are case sensitive i-e,
    have no relation to one another.

Php variable assignment

Value assignment

The simple type of assignment where variables are given values that are integer, string etc.
Valid examples include:
$sum=12+ “14”;

Reference assignment

Php4 introduced the ability to assign value by reference which means, the variable will hold content assigned to some other variable to which it is referenced.

$value1=”Hello” //value1=Hello
$value2=& $value1 //both equal to Hello

Variable scope

Php variables can have one of four scope types:

  1. Local Variable:Variable declared inside a function is called local. It can be referenced only inside the function.
  2. Global Variable:Variable that can be accessed in any part of the program. They are modified using global valuables.
  3. Function parameter:Parameters are arguments accepted by the function.Although these arguments take value from outside, they are no longer accessible after the function exits.
  4. Static Variable:These variable do not lose their values when the function exsits.

Leave a Reply

Your email address will not be published. Required fields are marked *