PHP If Else/Else If Statement


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Uninitialized str is set to 0, thus if condition fails.


  1. What will be the output of the following PHP code ?
    <?php
    $n = 5;
    if ($n++)
    print "Hello Interview Mania";
    else
    print "Hey Interview Mania";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    n is incremented after if which evaluates to false.



  1. What will be the output of the following PHP code ?
    <?php
    $n;
    if ($n == 0)
    print "Inter" ;
    else
    print "Mania";
    print "view"
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    else condition without brackets performs the following statements only.


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    echo does not return anything so if condition is empty.



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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    print returns 1 if it prints anything.