PHP If Else/Else If Statement


  1. What will be the output of the following PHP code ?
    <?php
    $num = 5;
    if ($num = $num&0)
    print $num ;
    else
    print "Else statement executed...";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    num&0 is 0,thus evaluated to false.


  1. What will be the output of the following PHP code ?
    <?php
    $p = 20;
    if ($p = $p&0)
    print $p ;
    else
    print "Executed...";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    p&0 is 0,thus evaluated to false.



  1. What will be the output of the following PHP code ?
    <?php
    $t = 11;
    if ($t = $t&0)
    print $t;
    else
    break;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    break is not defined for a if else ladder.


  1. What will be the output of the following PHP code ?
    <?php
    $p = 150;
    if ($p > 25)
    printf("Ajit");
    else if ($p > 35)
    printf("Ats");
    else if($p > 45)
    printf("Aju");
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In if else if one condition is satisfied then no other condition is checked.



  1. What will be the output of the following PHP code ?
    <?php
    $p = 25;
    $q = 50;
    $r = 15;
    if ($p / $q / $r)
    print "Interview";
    else
    print "Mania";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In php division returns a float that is a non zero value thus evaluates to true.