Thursday, 9 August 2018

PHP Fizz Buzz

Fizz Buzz is a math game that is based on division. To sum it up: Participants count up from the number one, saying “Fizz” when the number is divisible by three and “Buzz” when the number is divisible by five. If a number happens to be divisible by both three and five, then the phrase “Fizz Buzz” is used (the number 15 is a good example).
In the programming world, students and interviewees are often given the task of writing a piece of software that replicates the logic of the game.
Here is an example of the Fizz Buzz game being implemented in PHP:
As you can see, we made use of the % percentage sign, which is Modulus arithmetic operator in PHP. This operator will return the remainder of a given division sum. The number to the right of the modulus percentage sign is divided into the number on the left.
An example of PHP’s Modulus arithmetic operator in action:
The result is 2 because 17 divided by 5 = 3, with 2 being the remainder.

0 comments:

Post a Comment