3v4l.org

run code in 300+ PHP versions simultaneously
<?php const START = 1; const END = 100; /** * バックトレースの深さからインデックス相当の値を取得 * @return int */ function getI() { // debug_backtrace: バックトレースを配列で生成 // @see https://www.php.net/manual/ja/function.debug-backtrace.php // count: 配列の長さを取得 // @see https://www.php.net/manual/ja/function.count.php return count(debug_backtrace()) - 2 + START; } /** * 再帰で Fizz, Buzz を echo */ function echoFizzBuzz() { if (getI() % 15 === 0) { echo getI().': FizzBuzz'; } elseif (getI() % 3 === 0) { echo getI().': Fizz'; } elseif (getI() % 5 === 0) { echo getI().': Buzz'; } else { echo getI().': '.getI(); } echo "\n"; // 再帰で一次変数抜きにループを実現する // 再帰でバックトレースを深くしてインデックスを進める if (getI() < END) { echoFizzBuzz(); } } echoFizzBuzz();
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.14
1: 1 2: 2 3: Fizz 4: 4 5: Buzz 6: Fizz 7: 7 8: 8 9: Fizz 10: Buzz 11: 11 12: Fizz 13: 13 14: 14 15: FizzBuzz 16: 16 17: 17 18: Fizz 19: 19 20: Buzz 21: Fizz 22: 22 23: 23 24: Fizz 25: Buzz 26: 26 27: Fizz 28: 28 29: 29 30: FizzBuzz 31: 31 32: 32 33: Fizz 34: 34 35: Buzz 36: Fizz 37: 37 38: 38 39: Fizz 40: Buzz 41: 41 42: Fizz 43: 43 44: 44 45: FizzBuzz 46: 46 47: 47 48: Fizz 49: 49 50: Buzz 51: Fizz 52: 52 53: 53 54: Fizz 55: Buzz 56: 56 57: Fizz 58: 58 59: 59 60: FizzBuzz 61: 61 62: 62 63: Fizz 64: 64 65: Buzz 66: Fizz 67: 67 68: 68 69: Fizz 70: Buzz 71: 71 72: Fizz 73: 73 74: 74 75: FizzBuzz 76: 76 77: 77 78: Fizz 79: 79 80: Buzz 81: Fizz 82: 82 83: 83 84: Fizz 85: Buzz 86: 86 87: Fizz 88: 88 89: 89 90: FizzBuzz 91: 91 92: 92 93: Fizz 94: 94 95: Buzz 96: Fizz 97: 97 98: 98 99: Fizz 100: Buzz

preferences:
76.75 ms | 409 KiB | 5 Q