PHP Operators


  1. What will be the output of the following PHP code ?
    <?php
    $p = 8; $r = 7; $q = 15;
    $s = $p + $r == $q;
    print $s;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    First p and r are added and then tested if s = 15, which is true thus return 1.


  1. What will be the output of the following PHP code ?
    <?php
    $m = 10; $n = -8; $t = 2;
    $k = ++$m && ++$n || ++$t;
    echo $k;
    echo $m;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    111



  1. What will be the output of the following PHP code ?
    <?php
    $p = 10;
    $r = $p++; $q = ++$p;
    print $p;
    print $q;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    First case p is incremented after setting q to p.


  1. What will be the output of the following PHP code ?
    <?php
    $p = 20; $q = 20;
    if ($p = 12)
    $q--;
    echo $p;
    echo $q--;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    p is set to 20 in the if condition and q is post decremented in the print statement.



  1. What will be the output of the following PHP code ?
    <?php
    $p = 2; $q = 2; $r = 2;
    echo ++$p + ++$p+$p++; print $p++ + ++$q; print ++$r + $r++ + $p++;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Follow the order of post and pre increments.