PHP MCQs with answers Page - 14

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
print("this"."was"."a"."bad"."idea");
?>
  • (A) thiswasabadidea
  • (B) this was a bad idea
  • (C) nothing
  • (D) error

A

Admin • 831.35K Points
Coach

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

Code:
<?php
define("GREETING", "PHP is a scripting language");
echo $GREETING;
?>
  • (A) $GREETING
  • (B) no output
  • (C) PHP is a scripting language
  • (D) GREETING

A

Admin • 831.35K Points
Coach

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

Code:
<?php
define("__LINE__", "PHP is a scripting language");
echo __LINE__;
?>
  • (A) PHP is a scripting language
  • (B) __LINE__
  • (C) 2
  • (D) ERROR

A

Admin • 831.35K Points
Coach

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

Code:
<?php
define("NEW_GOOD_NAME_CONSTANT", "I have a value");
define("OLD_BAD_NAME_CONSTANT", NEW_GOOD_NAME_CONSTANT);
 
echo NEW_GOOD_NAME_CONSTANT;
echo OLD_BAD_NAME_CONSTANT; 
?>
  • (A) I have a value
  • (B) I have a valueI have a value
  • (C) I have a valueNEW_GOO_NAME_CONSTANTS
  • (D) ERROR

A

Admin • 831.35K Points
Coach

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

Code:
<?php
define("VAR_NAME","test"); 
${VAR_NAME} = "value"; 
echo VAR_NAME;
echo ${VAR_NAME}; 
?>
  • (A) test
  • (B) testtest
  • (C) testvalue
  • (D) error, constant value cannot be changed

A

Admin • 831.35K Points
Coach

Q. What is PHP?

  • (A) PHP is an open-source programming language
  • (B) PHP is used to develop dynamic and interactive websites
  • (C) PHP is a server-side scripting language
  • (D) All of the mentioned

A

Admin • 831.35K Points
Coach

Q. Which of the following is the correct syntax to write a PHP code?

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

A

Admin • 831.35K Points
Coach

Q. Which of the following is the correct way to add a comment in PHP code?

  • (A) #
  • (B) //
  • (C) /* */
  • (D) All of the mentioned

A

Admin • 831.35K Points
Coach

Q. Which of the following is the default file extension of PHP files?

  • (A) .php
  • (B) .ph
  • (C) .xml
  • (D) .html

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$x = 10;
$y = 20;
if ($x > $y && 1||1)
    print "1000 PHP MCQ" ;
else
    print "Welcome to McqBuddy";
?>
  • (A) no output
  • (B) Welcome to McqBuddy
  • (C) 1000 PHP MCQ
  • (D) error

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