PHP Variables


  1. What will be the output of the following PHP code ?
    <?php
    $n1 = 7.5;
    $n2 = 4;
    $n3 = 4;
    echo $n1 / $n2 / $n3;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    First $n1 / $n2 is evaluated then this is divided by $n3 therefore we get .46875.


  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.



  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
    $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.