I promise this isn't homework. I'm just a curious novice.
How does this:
function f($i){return $i<2?$i:f($i-1)+f($i-2);}
(written by someone smart)
produce the same result as this
function fibonacci($n, $arr = array(0,1)){
$arr[] = $arr[(count($arr) - 1)] + $arr[(count($arr) - 2)];
if (count($arr) == $n) return $arr[$n - 1];
else return fibonacci($n, $arr);
}
(mine)
I suppose I just don't get the syntax. Is there an if statement in there?