Created
July 31, 2020 01:25
-
-
Save shin1x1/eca4ab05cc4c6e2eafd480d9d64263ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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