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++;
}
?>  
  1. 2,4,
  2. 1,2,3,4,5,
  3. 2,4,6,
  4. 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,".

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.