SHARE
TWEET

PHP FizzBuzz Example

jessicakennedy1028 Sep 14th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fizzbuzz($fizz = 3, $buzz = 5, $total = 100, $echo = true){
  2.     $output = '';
  3.     for($i = 1; $i <= $total; $i++) {
  4.         $output .= ($i % $fizz == 0 && $i % $buzz == 0 ? "FizzBuzz\n" : ($i % $fizz == 0 ? "Fizz\n" : ($i % $buzz == 0 ? "Buzz\n" : ($echo ? $i."\n" : ''))));
  5.     }
  6.     return $output;
  7. }
  8.  
  9. echo fizzbuzz();
  10.  
  11. # or... define some fun in it:
  12.  
  13. echo fizzbuzz(6, 2, 150, true);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top