PHP MCQs with answers Page - 5

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
    function uppercase($string)
    {
        echo ucwords($string);
    }
    $wow = "uppercase";
    $wow("Time to live king size");
?> 
  • (A) Time To Live King Size
  • (B) Uppercase
  • (C) Time to live king size
  • (D) TIME TO LIVE KING SIZE

A

Admin • 831.35K Points
Coach

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

Code:
<?php
    function calc($num1, $num2)
    {
        $total = $num1 * $num2; 
    }
    $result = calc(42, 0);
    echo $result;    
?>
  • (A) 84
  • (B) 0
  • (C) Error
  • (D) 42

A

Admin • 831.35K Points
Coach

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

Code:
<?php
function constant()
{
    define("GREETING", "Welcome to Narnia",true);
    echo greeting;
}
?>
  • (A) ERROR
  • (B) GREETING
  • (C) Welcome to Narnia
  • (D) greeting

A

Admin • 831.35K Points
Coach

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

Code:
<?php
    echo str_pad("Salad", 5)." is good.";
?>
  • (A) Salad is good
  • (B) is good Salad
  • (C) SaladSaladSaladSaladSalad is good
  • (D) is good SaladSaladSaladSaladSalad

A

Admin • 831.35K Points
Coach

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

Code:
<?php
function colour()
{ 
    $colors = array("red", "green", "blue", "yellow"); 
    foreach ($colors as $value)
    {
        echo "$value <br>";
    }
}
colour();
?> 
  • (A) red green yellow blue
  • (B) green blue yellow red
  • (C) red green blue yellow
  • (D) red blue yellow green

A

Admin • 831.35K Points
Coach

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

Code:
<?php
function 2myfunc()
{
    echo "Hello World";
}
2myfunc();
?>
  • (A) ERROR
  • (B) No Output
  • (C) Hello World
  • (D) None of the mentioned

A

Admin • 831.35K Points
Coach

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

Code:
<?php
        function foo($msg)
        {
            echo "$msg";
        }
        $var1 = "foo";
        $var1("will this work");
    ?>
  • (A) error
  • (B) $msg
  • (C) 0
  • (D) will this work

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) - 1; $x++)	
    {
        if ($user[$x++] == "Shrek") 
		    continue;
        printf ($user[$x]); 
    }
?>
  • (A) Bale
  • (B) AshleyShrek
  • (C) BaleBlank
  • (D) AshleyBaleBlank

A

Admin • 831.35K Points
Coach

Q. Within a namespace, for accessing the built-in PHP classes you can prefix the class name with a . . . . . and let PHP look in the global class list.

  • (A) percent
  • (B) ampersand
  • (C) asterix
  • (D) backslash

A

Admin • 831.35K Points
Coach

Q. Which of the below namespace declaration is correct?

  • (A) namespace ORA:
  • (B) namespace 1_RA;
  • (C) namespace ORA;
  • (D) namespace ORA_#;