Php Control Structures (loop)(Engineering > Computer Science And Engineering > Php ) Questions and Answers

Question 1. What will be the output of the following PHP code ?$x = 0;if ($x++)print "hi";elseprint "how are u";
  1.    no output
  2.    error
  3.    hi
  4.    how are u
Explanation:-
Answer: Option D. -> how are u

Question 2. What will be the output of the following PHP code ?$a = 1;if ($a--)print "True";if ($a++)print "False";
  1.    no output
  2.    false
  3.    true
  4.    error
Explanation:-
Answer: Option C. -> true

Question 3. What will be the output of the following PHP code ?$x = 0;if ($x == 1)if ($x >= 0)print "true";elseprint "false";
  1.    true
  2.    no output
  3.    false
  4.    error
Explanation:-
Answer: Option B. -> no output

Question 4. What will be the output of the following PHP code?$x;if ($x)print "hi";elseprint "how are u";
  1.    how are u
  2.    no output
  3.    error
  4.    hi
Explanation:-
Answer: Option A. -> how are u

Question 5. What will be the output of the following PHP code ?$x;if ($x == 0)print "hi";elseprint "how are u";print "hello"
  1.    hihello
  2.    hi
  3.    how are uhello
  4.    no output
Explanation:-
Answer: Option A. -> hihello

Question 6. What will be the output of the following PHP code ?$a = 1;if (echo $a)print "True";elseprint "False";
  1.    no output
  2.    false
  3.    true
  4.    error
Explanation:-
Answer: Option D. -> error

Question 7. What will be the output of the following PHP code ?$a = 10;if (1)print "all";elseprint "some"elseprint "none";
  1.    none
  2.    some
  3.    all
  4.    error
Explanation:-
Answer: Option D. -> error

Question 8. What will be the output of the following PHP code ?$a = 10;if (0)print "all";ifelseprint "some"
  1.    no output
  2.    some
  3.    all
  4.    error
Explanation:-
Answer: Option D. -> error

Question 9. What will be the output of the following PHP code ?$a = 1;if (print $a)print "True";elseprint "False";
  1.    error
  2.    false
  3.    no output
  4.    true
Explanation:-
Answer: Option D. -> true

Question 10. What will be the output of the following PHP code ?$a = "";if ($a)print "all";ifelseprint "some";
  1.    some
  2.    all
  3.    error
  4.    no output
Explanation:-
Answer: Option A. -> some