pass function by reference
<p>Well, I know what references are and when it's use is obvious.</p>

<p>One thing I really can't get is that when it's better to pass function by reference.</p>

<pre><code>&lt;?php

//right here, I wonder why and when
function &amp;test(){

}
</code></pre>

<p>To avoid confusion, there're some examples as how I understand the references,</p>

<pre><code>&lt;?php

$numbers = array(2,3,4);

foreach ($numbers as &amp;$number){
   $number = $number * 2;
}

// now numbers is $numbers = array(4,6,8);


$var = 'test';
$foo = &amp;var; //now all changes to $foo will be affected to $var, because we've assigned simple pointer 



//Similar to array_push()
function add_key(&amp;$array, $key){
  return $array[$key];
}

//so we don't need to assign returned value from this function
//we just call this one

$array = array('a', 'b');

add_key($array,'c');
//now $array is ('a', 'b', 'c');
</code></pre>

<p>All benefits of using the references are obvious to me, except the use of "passing function by reference", </p>

<p>Question: When to pass function by reference (I've searched answer here, but still can't grasp this one)
Thanks </p>
