Assign variable by reference in PHP

Description

The following code shows how to assign variable by reference.

Example


/*from  w  w w.j  av a2s  . co  m*/
<?php
  //create variable
  $a = "Apple";

  //create references
  $b = &$a;

  //change value of both $a and $b
  $a = "Ball";

  //remove $a
  unset($a);

  //prints Ball
  print($b);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition