Skip to content

Instantly share code, notes, and snippets.

@davidstanley01
Created May 19, 2016 13:47
Show Gist options
  • Select an option

  • Save davidstanley01/2e1d3fc87c66caa60db0349ef26a9664 to your computer and use it in GitHub Desktop.

Select an option

Save davidstanley01/2e1d3fc87c66caa60db0349ef26a9664 to your computer and use it in GitHub Desktop.

Revisions

  1. davidstanley01 created this gist May 19, 2016.
    21 changes: 21 additions & 0 deletions generator.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?php

    function getFizzBuzz($max) {
    for ($i = 0; $i < $max; $i++) {
    $string = null;
    $string = ($i % 15) === 0 && is_null($string) ? 'FizzBuzz' : null;
    $string = ($i % 3) === 0 && is_null($string) ? 'Fizz' : $string;
    $string = ($i % 5) === 0 && is_null($string) ? 'Buzz' : $string;

    yield $string;
    }
    }

    $max = 1000;

    echo '<ul style="list-style-type:none;">';
    foreach (getFizzBuzz($max) as $key => $value) {
    echo echo sprintf('<li>%s - %s</li>', $key, $value);
    }
    echo '</ul>';