PHP MCQs with answers Page - 3

Here, you will find a collection of MCQ questions on PHP. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 831.35K Points
Coach

Q. Which of the conditional statements is/are supported by PHP?
1. if statements
2. if-else statements
3. if-elseif statements
4. switch statements

  • (A) Only 1
  • (B) 1, 2 and 4
  • (C) 2, 3 and 4
  • (D) All of the mentioned.

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$team = "arsenal";
switch ($team) 
{
case "manu":
  echo "I love man u";
case "arsenal":
  echo "I love arsenal";
case "manc":
  echo "I love manc"; 
}
?>
  • (A) I love arsenal
  • (B) Error
  • (C) I love arsenalI love manc
  • (D) I love arsenalI love mancI love manu

A

Admin • 831.35K Points
Coach

Q. Which of the looping statements is/are supported by PHP?
1. for loop
2. while loop
3. do-while loop
4. foreach loop

  • (A) 1 and 2
  • (B) 1, 2 and 3
  • (C) All of the mentioned
  • (D) None of the mentioned

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$user = array("Ashley", "Bale", "Shrek", "Blank");
for ($x=0; $x < count($user); $x++)
{
  if ($user[$x] == "Shrek") continue;
  printf ($user[$x]); 
}
?>
  • (A) AshleyBale
  • (B) AshleyBaleBlank
  • (C) ShrekBlank
  • (D) Shrek

A

Admin • 831.35K Points
Coach

Q. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

  • (A) 12
  • (B) 1
  • (C) Error
  • (D) 5

A

Admin • 831.35K Points
Coach

Q. What is the value of $a and $b after the function call?

Code:
<?php
function doSomething( &$arg ) 
{
  $return = $arg;
  $arg += 1;
  return $return;	
}
$a = 3;
$b = doSomething( $a );
?>
  • (A) a is 3 and b is 4
  • (B) a is 4 and b is 3
  • (C) Both are 3
  • (D) Both are 4

A

Admin • 831.35K Points
Coach

Q. Who is the father of PHP?

  • (A) Rasmus Lerdorf
  • (B) Willam Makepiece
  • (C) Drek Kolkevi
  • (D) List Barely

A

Admin • 831.35K Points
Coach

Q. How does the identity operator === compare two values?

  • (A) It converts them to a common compatible data type and then compares the resulting values
  • (B) It returns True only if they are both of the same type and value
  • (C) If the two values are strings, it performs a lexical comparison
  • (D) It bases its comparison on the C strcmp function exclusively

A

Admin • 831.35K Points
Coach

Q. What should be the correct syntax to write a PHP code?

  • (A) < php >
  • (B) < ? php ?>
  • (C)
  • (D)

A

Admin • 831.35K Points
Coach

Q. Under what circumstance is it impossible to assign a default value to a parameter while declaring a function?

  • (A) When the parameter is Boolean
  • (B) When the function is being declared as a member of a class
  • (C) When the parameter is being declared as passed by reference
  • (D) When the function contains only one parameter

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ