PHP Operators


  1. What will be the output of the following PHP code ?
    <?php
    $t = 5;
    if ($t-- == ++$t)
    {
    echo $t;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    First $t = 5 is compared to and then decremented, then incremented and compared to $t = 5.


  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.


  1. What will be the output of the following PHP code ?
    <?php
    $str1 = "Hello ";
    $str2 = "Interview ";
    $str3 = "Mania ";
    $str1 .= $str2 .= $str3 ;
    echo $str1;
    echo $str2;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The str1 .= str2 is a shorthand for str1 = str1.str2 and this is evaluated from right to left.



  1. What will be the output of the following PHP code ?
    <?php
    $k = 15;
    --$k;
    echo $k++;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The + operator does union of arrays in that order, then the === operator compares key and value pairs.