The code gives 0
because it is missing a return
. Compare with the following which (when corrected as shown) produces 36
, as reasoned in the other answer.
function a($n){
// Since b($n) doesn't return a value in the original,
// then NULL * $n -> 0
return ( b($n) * $n);
}
function b(&$n){
// But if we return the value here then it will work
// (With the initial condition of $n==5, this returns 6 AND
// causes the $n variable, which was passed by-reference,
// to be assigned 6 such that in the caller
// it is 6 * $n -> 6 * 6 -> 36).
return ++$n;
}
echo a(5);
See Passing by Reference for how function b(&$n)
works above; if there signature was function b($n)
the result would have been 30.