Posted By

ariellephan on 07/22/11


Tagged

mutiple


Versions (?)

FizzBuzz


 / Published in: PHP
 

2 ways to go about this problem

  1. <?php
  2. for ($i=1; $i <=100; $i++)
  3. {
  4. $a=$i/3; $b=$i/5 ;
  5. if (is_int($a) && is_numeric($b)){echo "Fizz, ";}
  6. elseif ( is_int($b) && is_numeric($a)) {echo "Buzz, ";}
  7. elseif ( is_int($a) && is_int($b)) {echo "FizzBuzz, ";}
  8. else {echo "$i, ";}
  9. }
  10.  
  11. echo "<br/>";
  12. for ($i=1; $i <=100; $i++)
  13. {
  14.  
  15. if ( $i%3==0 && $i%5 !== 0 ){echo "Fizz, ";}
  16. elseif ( $i%5==0 && $i%3 !== 0 ) {echo "Buzz, ";}
  17. elseif ( $i%3==0 && $i%5 == 0 ) {echo "FizzBuzz, ";}
  18. else {echo "$i, ";}
  19. }
  20. ?>

Report this snippet  

You need to login to post a comment.