Today,I had a very interesting experience about PHP.
Here is a question about FizzBuzz:
The aim of this test is to implement the FizzBuzz problem.
FizzBuzz is defined for the “natural numbers” (numbers greater than zero) as:
When divisible by 3, you should return “Fizz”.
When divisible by 5, you should return “Buzz”.
When divisible by both 3 and 5, you should return “FizzBuzz”.
When divisible by neither, you should return the number itself.
The test is expected to take around 10 minutes. When you are ready to take it, please follow the link below:
This test will require you to solve the exercise in the Php programming language.
Actually this is an easy question. The only thing you need is if and elseif.
However,when I clicked the link of this question. I realized that I was wrong.
The test program requires a class of PHP. To be honest ,this is the first time I know that class is important in PHP program. In my undergraduate study I never had an opportunity to use class in PHP.
As a result,I had to google some information about class and finally completed the exercise after 1 hour…
Here is some tips about this question:
1.class in PHP
some time we will use class to solve problem. It is common to use a class like that:
10 is the value of input and fizz() will return a value to $fizzbuzz.
This is a really common function. You can not use it as a normal function in class. The main responsibility for this function is to declare values.
Today I have to use one of the magic methods:_tostring()
This function is used when the class is treated as a string.That is to say,we can only return values in string type.
Here is an example:
Sometimes we have to use it to return some integer.Then we will have to use another important point. We need to change the integer into string.
Actually,this exercise is really useful and I have learned a lot from it,although
I may have lost the opportunity for interview…