PHP Variables


  1. What will be the output of the following PHP code ?
    <?php
    $m = 15;
    $n = 5;
    $t = 7;
    echo ($m % ($n) + $t);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The innermost bracket is evaluated first, since it covers only variable n it is as good as not using brackets.


  1. What will be the output of the following PHP code ?
    <?php
    $p = 22;
    $q = 5;
    $r = 4;
    echo $p % $q % $r;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The expression is considered as ($p%$q)%r in this case (22%5)%4 which is 2.



  1. What will be the output of the following PHP code ?
    <?php
    $p = 11;
    $q = 3;
    echo $p % $q;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    % is the modulo operator. Unlike in C we can use it get reminder or floating point numbers in PHP.


  1. What will be the output of the following PHP code ?
    <?php
    $a = 41;
    $b = 13;
    $c = 10;
    $d = $c + $a + $b;
    echo "$d";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    Normal addition of variables a, b and c occurs and result of 64 will be displayed.



  1. What will be the output of the following PHP code ?
    <?php
    $n1 = 14;
    $n2 = 31;
    $n3 = 11;
    echo "$n1 = $n1 + $n2 + $n3";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Again since the variables are inside double quotes we get this result.