Last active
August 15, 2017 15:04
-
-
Save dreanmer/e49faca778a2cc0efc21fa2d688b6f80 to your computer and use it in GitHub Desktop.
Fizz Buzz solution one if (with regex)
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 | |
$result = ''; | |
for($i=1;$i<=100;$i++){ | |
if(!($i%3)){ | |
$result .= 'm'; | |
} | |
$result .= $i . "\n"; | |
} | |
$result = preg_replace("/m\d*(0|5)\n/", "FizzBuzz\n", $result); | |
$result = preg_replace("/\d*(0|5)\n/", "Buzz\n", $result); | |
$result = preg_replace("/m\d+\n/", "Fizz\n", $result); | |
echo $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment