class Fibonacci
{
function __construct() {
}
static function fib($total, $initial, $next) {
if ($total > 0) {
Fibonacci::fib($total - 1, $next, $next + $initial);
echo " " . $initial;
}
}
public static function main()
{
$total = 6;
echo "Fibonacci series of " . $total . " Elements :";
Fibonacci::fib($total, 0, 1);
$total = 10;
echo "\nFibonacci series of " . $total . " Elements :";
Fibonacci::fib($total, 0, 1);
}
}
Fibonacci::main();
/*
run:
Fibonacci series of 6 Elements : 5 3 2 1 1 0
Fibonacci series of 10 Elements : 34 21 13 8 5 3 2 1 1 0
*/