PHP For Loops


  1. What will be the output of the following PHP code ?
    <?php
    $name = array("Neha", "Sumi", "Abhay");
    for (;count($name) < 5;)
    {
    if (count($name) == 3)
    print $name;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Array to string conversion error.


  1. What will be the output of the following PHP code ?
    <?php
    $p = 0;
    for(++$p; ++$p; ++$p)
    {
    print $p;
    if ($p == 6)
    break;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on.



  1. What will be the output of the following PHP code ?
    <?php
    for ($b = 0; $b = -5; $b = 1)
    {
    print $b;
    if ($b != 2)
    break;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on .


  1. What will be the output of the following PHP code ?
    <?php
    for(;;)
    {
    print "25";
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    There is no check condition to stop the execution of the loop.



  1. What will be the output of the following PHP code ?












  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Follow the trace of a, b prints 3 – a no of spaces for each a, b prints a stars for each loop.