PHP Operators


  1. What will be the output of the following PHP code ?
    <?php
    $num = 8;
    while (--$num > 0 || ++$num)
    {
    print $num;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    As it is || operator the second expression is not evaluated till num becomes 1 then it goes into a loop.


  1. What will be the output of the following PHP code ?
    <?php
    $n = 15;
    while (--$n > 0 && ++$n)
    {
    print $n;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    As it is && operator it is being incremented and decremented continuously.



  1. What will be the output of the following PHP code ?
    <?php
    $k = 10;
    while (--$k > 0)
    {
    $k++;
    print $k;
    print "Interview Mania";
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    k is decremented in the first while execution and then continuously incremented back.


  1. What will be the output of the following PHP code ?
    <?php
    $s = 4;
    $t = 8;
    $s *= $t /= $s;
    echo $s, $t;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Expression is evaluated from right to left.



  1. What will be the output of the following PHP code ?
    <?php
    $p = 5;
    $q = 6;
    if (++$p == $q++)
    {
    echo "true ", $q, $p;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    p is preincremented and q is post incremented thus both are 6 in the if condition, later q is increment.