PHP If Else/Else If Statement


  1. What will be the output of the following PHP code ?
    <?php
    $num = "";
    if ($num)
    print "Second";
    else
    print "First";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Empty string is evaluated to 0.


  1. What will be the output of the following PHP code ?
    <?php
    $n1 = 17;
    $n2 = 19;
    if ($n1 > $n2 + $n2 != 3)
    print "Interview" ;
    else
    print "Mania";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Expression evaluates to true.



  1. What will be the output of the following PHP code ?
    <?php
    $str = "s";
    if ($str)
    print "Executed....";
    else
    print "Not Executed...";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The value of str is evaluated to 1 as it has a value.


  1. What will be the output of the following PHP code ?
    <?php
    $num1 = 25;
    $num2 = 27;
    if ($num1 > $num2 && 1||1)
    print "Manjesh" ;
    else
    print "Ojha";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Expression evaluates to true.



  1. What will be the output of the following PHP code ?
    <?php
    $num = 5;
    if (5)
    print "First";
    if
    else
    print "Second";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    No else statement to end the if statement.