Skip to content

Instantly share code, notes, and snippets.

@hassanuos
Last active March 26, 2021 12:40
Show Gist options
  • Save hassanuos/019334373dec20a345903af3d97ef26a to your computer and use it in GitHub Desktop.
Save hassanuos/019334373dec20a345903af3d97ef26a to your computer and use it in GitHub Desktop.
simple interview example code
//Write a program that prints the numbers 1 to 100, but for every multiple of 3 write "Fizz",
//for every multiple of 5 write "Buzz", for every multiple of 3 and 5 write "FizzBuzz"
//OutPut
//1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz...
//Code Here Below
$inputVal = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
foreach($inputVal as $number){
if($number%3 === 0){
$num[] = "Fizz";
}elseif($number%5 === 0){
$num[] = "Fizz";
}elseif(($number%3 === 0) && ($number%5 === 0)){
$num[] = "FizzBuzz";
}else{
$num[] = $number;
}
}
print_r($num);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment