Learn with Yasir

Share Your Feedback

PHP Basics MCQs – Multiple Choice Questions for Beginners and Interviews


Sharpen your PHP skills with these multiple choice questions on PHP basics. Great for beginners, students, and interview preparation. Start practicing now!.

📝 Multiple Choice Questions

🟢 Beginner

Q1. What is the output of the following PHP code?

<?php
    echo "Hello ";
    echo "World!";
?>
  • 🟢 A. Hello World!
  • 🔵 B. Hello World
  • 🟠 C. World Hello
  • 🔴 D. Error
Answer

Hello World!

The `echo` statement is used to output the text. In this case, "Hello" and "World!" are printed sequentially without any issues.


🟡 Intermediate

Q1. What is the output of the following PHP code?

<?php
    $x = 5;
    $y = 10;
    echo $x + $y;
?>
  • 🟢 A. 15
  • 🔵 B. 510
  • 🟠 C. 5 + 10
  • 🔴 D. Error
Answer

15

The `+` operator is used to add two numbers. In this case, the sum of `$x` and `$y` (5 + 10) results in 15.


Q2. What is the output of the following PHP code?

<?php
    $a = 10;
    $b = 5;
    $a = $a / $b;
    echo $a;
?>
  • 🟢 A. 2
  • 🔵 B. 5
  • 🟠 C. 10
Answer


🔴 Advanced

Which component in XAMPP is used to serve web pages? A. MySQL B. Apache C. FileZilla D. Mercury ✅ Answer: B. Apache

  1. What is the default folder in XAMPP to save your website files? A. /htdocs B. /public_html C. /www D. /webroot ✅ Answer: A. /htdocs

  2. What is the default port number for Apache in XAMPP? A. 21 B. 80 C. 3306 D. 443 ✅ Answer: B. 80

  3. Which component of XAMPP is used to manage databases? A. Apache B. phpMyAdmin C. FileZilla D. Tomcat ✅ Answer: B. phpMyAdmin

  4. Which file extension is used for PHP files saved in XAMPP? A. .html B. .php C. .js D. .exe ✅ Answer: B. .php

  5. Which of the following is a client-side scripting language? A. PHP B. JavaScript C. Python D. ASP.NET ✅ Answer: B. JavaScript

Which scripting language runs on the server and generates dynamic content before sending it to the browser? A. HTML B. CSS C. PHP D. JavaScript ✅ Answer: C. PHP

  1. What is the main purpose of client-side scripting? A. To store data in a database B. To control the web server C. To handle user interface interactions D. To validate server responses ✅ Answer: C. To handle user interface interactions

  2. Which scripting runs after the webpage is loaded in the browser? A. Server-side B. Client-side C. Both D. Neither ✅ Answer: B. Client-side

  3. What is a common use of server-side scripting? A. Creating animations B. Interacting with the database C. Changing the font style D. Adjusting layout with CSS ✅ Answer: B. Interacting with the database

  4. Which combination is commonly used in full-stack web development? A. HTML and Excel B. JavaScript (client) and PHP (server) C. PHP (client) and HTML (server) D. CSS (client) and MySQL (client) ✅ Answer: B. JavaScript (client) and PHP (server)

Matching Questions

Match the scripting language with its appropriate category:

Language Type
A. JavaScript 1. Server-side
B. PHP 2. Client-side
C. Python  
D. HTML  
E. CSS  

Correct Answers:

  • A → 2 (Client-side)
  • B → 1 (Server-side)
  • C → 1 (Server-side)
  • D → 2 (Client-side) (markup, not scripting)
  • E → 2 (Client-side) (styling, not scripting)