Reference   PHP


Summary

You can pass a variable by reference.


Requirements

None.


<?php

$a = [];
$a['name'] = 'apple';
$b =& $a['name'];

echo "$b / ";

$b = 'banana';

echo $a['name'];

function assign(&$to, $str) { // $to is a reference variable
    $to = $str;
}

assign($a['name'], 'lemon');

echo " / $b";


Result

apple / banana / lemon

References


Tags

#pointer  #reference 


[ Edit (Author only) ]