PHP MCQs with answers Page - 7

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. What will be the output of the following PHP code ?

Code:
<?php
$color = red;
echo "$color" . red ;
?>
  • (A) red red
  • (B) red
  • (C) error
  • (D) nothing

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$color1 = red;
$color2 = green;
echo "$color1"."$color2";
?>
  • (A) red green
  • (B) red
  • (C) green
  • (D) error

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$color = "red";
$color = "green";
echo "$color";
?>
  • (A) red
  • (B) green
  • (C) red green
  • (D) error

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$color1 = "red";
$color2 = "green";
echo "$color1" . "$color2";
?>
  • (A) red
  • (B) green
  • (C) red green
  • (D) redgreen

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$color1 = "red";
$color2 = "green";
echo "$color1" + "$color2";
?>
  • (A) redgreen
  • (B) 0
  • (C) red green
  • (D) error

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$color1 = "red";
$color2 = "red";
echo "$color1" + "$color2";
?>
  • (A) redgreen
  • (B) red green
  • (C) 0
  • (D) 1

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$color1 = "red";
$color2 = "1";
echo "$color1" + "$color2";
?>
  • (A) red1
  • (B) red 1
  • (C) 0
  • (D) 1

A

Admin • 831.35K Points
Coach

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

Code:
<?php
function doSomething(&$argument) 
    {
        $Result = $argument;
        $argument += 1;
        return $Result;	
    }
$n = 5;
$m = doSomething($n);
echo "n = " . $n . " and m = " . $m;
?>
  • (A) n = 6
  • (B) n = 6 and m = 5
  • (C) m = 6
  • (D) Error

A

Admin • 831.35K Points
Coach

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

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

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$user = array("Ats ", "Ajit ", "Rahul ", "Aju ");
for ($str=0; $str < count($user); $str++)	{
if ($user[$str] == "Rahul ") continue;
printf ($user[$str]); 
}
?>
  • (A) Error
  • (B) Rahul
  • (C) Ats Ajit Aju
  • (D) Ats Ajit Rahul Aju

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