fork download
  1. <?php
  2.  
  3. $foo_count = $bar_count = 0;
  4. foreach (range(1, 20) as $number ) {
  5. echo $number;
  6. echo '&nbsp;';
  7.  
  8. if ($number % 3 == 0 && $number %5 == 0) {
  9. echo "foobar ";
  10. $foo_count++;
  11. $bar_count++;
  12.  
  13. } elseif ($number % 3 == 0) {
  14. echo "foo ";
  15. $foo_count++;
  16.  
  17. } elseif ($number % 5 == 0) {
  18. echo "bar ";
  19. $bar_count++;
  20. }
  21. }
  22.  
  23. echo "<br>\n";
  24. echo "foo: $foo_count times listed<br>\n";
  25. echo "bar: $bar_count times listed<br>";
Success #stdin #stdout 0.02s 24576KB
stdin
Standard input is empty
stdout
1&nbsp;2&nbsp;3&nbsp;foo 4&nbsp;5&nbsp;bar 6&nbsp;foo 7&nbsp;8&nbsp;9&nbsp;foo 10&nbsp;bar 11&nbsp;12&nbsp;foo 13&nbsp;14&nbsp;15&nbsp;foobar 16&nbsp;17&nbsp;18&nbsp;foo 19&nbsp;20&nbsp;bar <br>
foo: 6 times listed<br>
bar: 4 times listed<br>