I want to execute a FizzBuzz function for integer values between 1 and $max.
The return value depends on the number of a specific positive integer value received as an argument,
・ If the number is a multiple of 3, the return value is "Fizz"
・ If the number is a multiple of 5, the return value is "Buzz"
-If the number is a multiple of 3 and a multiple of 5, the return value is "FizzBuzz"
・ If none of the above is satisfied, the numerical value itself is used as the return value. It is a thing of the condition.
Since I want to run the fizzbuzz function with an integer value between 1 and $max, I want to leave out of the fizzbuzz function.
I do not print in the Fizzbuzz function, but want to print the return value after returning once.
Error message
None in particular
Points that do not meet the above specifications
code
<? php
function fizz_buzz () {
$max = 100;
for ($n = 1;$n<= $max;$n ++) {
if ($n% 15 == 0) {
print "FizzBuzz" .PHP_EOL;
}
elseif ($n% 3 == 0) {
print "Fizz" .PHP_EOL;
}
elseif ($n% 5 == 0) {
print "Buzz" .PHP_EOL;
}
else {
print $n.PHP_EOL;
}
}
}
fizz_buzz ()
?>
Source code
None
Supplemental information (FW/tool version)Cloud9
-
Answer # 1
-
Answer # 2
I wrote it to be good without changing ini.
By the way, I dare put a description that a beginner cannot explain.
Related articles
- php - i want to identify and correct the cause of the page feed error that occurs in wordpress
- [php/mysql] sql syntax error of sqlstate [42000] occurs
- php - i get an error when submitting a laravel 5550 form
- php - i get an error in vuejs when trying to deploy to production (laravel)
- cakephp 4: i get an error when uploading a file without input
- php - sqlstate [hy000]: general error: 1364 user registration is not possible due to an error
- i want to solve the ssl error "dh key too small in" that appears when using the national diet library api with php
- i don't know how to resolve the php syntax error required to log in
- laravel php artisan config: 500 error when caching
- [php/xampp] an error occurs when setting the include path
- php: there is an error in the insert into line and it cannot be resolved
- php: tell us about the application of the fizzbuzz problem!
- when i upgraded the php spreadsheet, i got an error
- php - 404 not found nginx/1135 error resolution
- php - vlaravel form request does not show error statement
- php - [wp] an error is displayed in the item part added to the user information in advanced custom field
- php parse error: syntax error, unexpected'class' (t_class) error
- php - "doesn't have a default value" error when performing seeding
- php - an error that i personally cannot solve
- php - variable undefined error when updating view file with laravel
Since it looks like an assignment, answer the round throw. I will not explain.
We do not take any responsibility for submitting the document as it is or not.
Don't forget that the principle is "Don't write incomprehensible code".