Created
March 15, 2024 21:47
-
-
Save ruthlessfish/3f2b573a162bf3efbd7d3a8a67a11c8d to your computer and use it in GitHub Desktop.
Fizz BUzz
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
#!/usr/bin/env php | |
<?php | |
// default value | |
$n = 10; | |
// set custom n value | |
if (isset($argv[1]) && is_int($argv[1])) { | |
$n = $argv[1]; | |
} | |
$res = array(); | |
for ($i = 1; $i <= $n; $i++) { | |
$str = ""; | |
if ($i % 5 == 0) { | |
$str .= "fizz"; | |
} | |
if ($i % 3 == 0) { | |
$str .= "buzz"; | |
} | |
if ($str == "") { | |
$str = "$i"; | |
} | |
array_push($res, $str); | |
} | |
echo implode(",", $res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment