Q. What will be the output of the following PHP code ?

Code:
<?php
switch($k)
{
case 2:
    print "First";
    break;
case k:
    print "Second";
    break;
}
?>
  • (A) Undefined variable: k
  • (B) First
  • (C) Second
  • (D) Nothing
πŸ’¬ Discuss
βœ… Correct Answer: (A) Undefined variable: k
Explanation: Case cannot be defined by a variable.

Q. What will be the output of the following PHP code ?

Code:
<?php
$n = 128;
switch($n)
{
case "n":
    print "Welcome to";
    break;
case 128:
    print "MCQ";
    break;
default:
    print "BUDDY";
}
?>
  • (A) BUDDY
  • (B) Error
  • (C) MCQ
  • (D) Welcome to
πŸ’¬ Discuss
βœ… Correct Answer: (C) MCQ

Q. What will be the output of the following PHP code ?

Code:
<?php
$p = "1";
$p = 1;
$q = 1;
switch($p)
{
case $p * $q: 
    print "Hello";
    break;
case $p / $q:
    print "Hey";
    break;
default:
    print "Bye";
}
?>
  • (A) Hello
  • (B) Hey
  • (C) Bye
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) Hello

Q. What will be the output of the following PHP code ?

Code:
<?php
$opt = "1";
switch($opt)
{
case 1:
    break;
    print "First Statement";
case 2:
    print "Second Statement";
    break;
default:
    print "Third Statement";
}
?>
  • (A) First Statement
  • (B) Second Statement
  • (C) Third Statement
  • (D) Nothing
πŸ’¬ Discuss
βœ… Correct Answer: (D) Nothing
Explanation: As break is provided before print statement in case 1 it breaks the loop before printing.

Q. What will be the output of the following PHP code ?

Code:
<?php
$opt = "1";
switch ($opt)
{
case 1:
    print "Hello ";
case 2:
    print "MCQ";
default:
    print "Buddy";
}
?>
  • (A) Hello MCQ Buddy
  • (B) MCQ
  • (C) Buddy
  • (D) Hello
πŸ’¬ Discuss
βœ… Correct Answer: (A) Hello MCQ Buddy
Explanation: As break is not provided it executes all the cases.

Q. What is the name of the scripting engine in PHP?

  • (A) SpiderMonkey
  • (B) Zend Engine
  • (C) VBScript
  • (D) CS-Script
πŸ’¬ Discuss
βœ… Correct Answer: (B) Zend Engine

Q. Default file extension of php file is

  • (A) .html
  • (B) .xml
  • (C) .hphp
  • (D) .php
πŸ’¬ Discuss
βœ… Correct Answer: (D) .php

Q. Can PHP send and receive cookies?

  • (A) True
  • (B) False
  • (C) PHP new version can not send and receive cookies but the old version can.
  • (D) PHP older version can not send and receive cookies but the new version can.
πŸ’¬ Discuss
βœ… Correct Answer: (A) True

Q. PHP runs on which platform?

  • (A) Linux
  • (B) Mac OS X
  • (C) Windows
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above

Q. Does PHP support multiple inheritances?

  • (A) Yes
  • (B) No
  • (C) Single and multiple inheritances are supported.
  • (D) Single and multilevel inheritance is supported.
πŸ’¬ Discuss
βœ… Correct Answer: (B) No