Home »
MCQs »
PHP MCQs
What will be the output of the following PHP code (22)?
92. What will be the output of the following PHP code?
<?php
$counter = 1;
while ($counter++ <= 5)
{
echo $counter, ",";
$counter++;
}
?>
- 2,4,
- 1,2,3,4,5,
- 2,4,6,
- 1,2,4,
Answer: C) 2,4,6,
Explanation:
In the while expression, the statement $counter++ is a post-increment operation and it executes after checking the condition. Thus, the output will be "2,4,6,".