Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created July 31, 2020 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/eca4ab05cc4c6e2eafd480d9d64263ba to your computer and use it in GitHub Desktop.
Save shin1x1/eca4ab05cc4c6e2eafd480d9d64263ba to your computer and use it in GitHub Desktop.
<?php
function fib_match(int $i): int
{
return match($i) {
1,2 => 1,
default => fib_match($i - 1) + fib_match($i - 2),
};
}
function fib_switch(int $i): int
{
switch ($i) {
case 1:
return 1;
case 2:
return 1;
default:
return fib_switch($i - 1) + fib_switch($i - 2);
}
}
var_dump(fib_match(10));
var_dump(fib_switch(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment