Answer & Solution
while loop
to print numbers from 1 to 5. The loop condition is $x <= 5
, and within the loop, $x
is incremented by 1 in each iteration, and the value of $x
is printed.
";
$x++;
}
?> | PHP | MYTAT">
";
$x++;
}
?> | PHP | MYTAT">
<?php
$x = 1;
while ($x <= 5) {
echo 'The number is: $x
';
$x++;
}
?>
while loop
to print numbers from 1 to 5. The loop condition is $x <= 5
, and within the loop, $x
is incremented by 1 in each iteration, and the value of $x
is printed.
Which PHP loop is typically used for iterating over the elements of an array?
A). for loop
B). while loop
C). do-while loop
D). foreach loop
Which of the following PHP control structures is used to evaluate an expression against multiple possible cases?
A). if statement
B). for loop
C). switch statement
D). while loop
What will be the output of the following PHP code?<?php
for ($i = 1; $i <= 5; $i++) {
if ($i == 3) {
continue;
}
echo 'The number is: $i
';
}
?>
A). The number is: 1
The number is: 2
The number is: 3
B). The number is: 1
The number is: 2
The number is: 4
The number is: 5
C). The number is: 3
D). The number is: 4
Which control structure in PHP is used to execute a block of code if a specified condition is true, and another block of code if the condition is false?
A). if-else statement
B). for loop
C). switch statement
D). while loop
What is the output of the following PHP code?<?php
$i = 1;
while ($i <= 3) {
echo 'The number is: $i
';
$i++;
if ($i == 2) {
continue;
}
}
?>
A). The number is: 1
The number is: 2
The number is: 3
B). The number is: 1
The number is: 3
C). The number is: 2
The number is: 3
D). The number is: 1
What will be the output of the following PHP code?<?php
$x = 5;
do {
echo 'The number is: $x
';
$x++;
} while ($x <= 3);
?>
A). The number is: 5
B). The number is: 5
The number is: 6
C). The number is: 5
The number is: 4
D). The number is: 6
Which control structure in PHP is used to execute a block of code repeatedly as long as a specified condition is true?
A). if statement
B). for loop
C). switch statement
D). while loop
Which PHP control structure is used to execute a block of code based on the evaluation of multiple conditions?
A). if-else statement
B). for loop
C). switch statement
D). while loop
What does the following PHP code snippet do?<?php
$colors = array('Red', 'Green', 'Blue');
foreach ($colors as $color) {
echo 'Color: $color
';
}
?>
A). It prints 'Color: Red'
B). It prints 'Color: Green'
C). It prints 'Color: Blue'
D). It prints all the elements of the
$colors
array
What is the output of the following PHP code?<?php
$x = 0;
while ($x < 3) {
echo 'The number is: $x
';
$x++;
}
?>
A). The number is: 0
The number is: 1
The number is: 2
B). The number is: 3
C). The number is: 0
D). The number is: 1