PHP Operators


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The first condition itself fails thus the loop exits.


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    (–$p > ++$p) evaluates to 2 but -2 makes it enters the loop and prints p which is 2.



  1. What will be the output of the following PHP code ?
    <?php
    echo 10 * 15 / 12 + 14
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Operator precedence order must be followed.


  1. What will be the output of the following PHP code ?
    <?php
    $p = 20;
    $q = 10;
    if ($p || ($q = $p + 10)) {
    echo "True";
    }
    echo $q;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    In if condition when the first case is 1 and is an || operation then the second command is not executed.



  1. What will be the output of the following PHP code ?
    <?php
    $n = 10;
    $m = 10;
    if ($n && ($m = $n + 10)) {
    echo "True";
    }
    echo $m;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    In if condition when the first case is 10 and is an && operation then the second command is executed.