php & symbol before variable code example

Example: php & before variable

It passes a reference to the variable so when any variable assigned the reference 
is edited, the original variable is changed. They are really useful when making 
functions which update an existing variable. Instead of hard coding which variable 
is updated, you can simply pass a reference to the function instead.

Example

<?php
    $number = 3;
    $pointer = &$number;  // Sets $pointer to a reference to $number
    echo $number."<br/>"; // Outputs  '3' and a line break
    $pointer = 24;        // Sets $number to 24
    echo $number;         // Outputs '24'
?>

Tags:

Php Example