1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【php】phpでfizzbuzzを解け

Last updated at Posted at 2021-05-23
<h1>fizzbuzz</h1>

<?php
$i =0;
while ($i <= 100){
  $i++;
  if ($i % 3 === 0 && $i % 5 === 0){
     echo "FizzBuzz". '<br>';
  }elseif($i % 3 === 0){
    echo "Fizz". '<br>';
  }elseif($i % 5 === 0){
    echo "Buzz". '<br>';
  }
}

?>

上級者用


<?php
function get_fizzbuzz($number){
  if($number % 15 === 0){
    return 'FizzBuzz!';
  }
  if($number % 3 === 0) {
    return 'Fizz!';
  }
  if($number % 5 === 0) {
    return 'Buzz!';
  }
  return $number;
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <title>FizzBuzz</title>
</head>
<body>
    <h1>FizzBuzz</h1>
    <table>
        <?php for($i = 1; $i <= 100; $i++){ ?>
            <?php echo get_fizzbuzz($i); ?><br>
        <?php } ?>
    </table>
</body>
</html>

image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?