Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PHP Preliminary Examination

Total questions: 40

Worksheet time: 20mins

Name
Class
Date
1.

What does PHP stand for?

a)

Programming Hypertext Page

b)

Preprocessor Hyperlink Page

c)

PHP: Hypertext Preprocessor

d)

Personal Home Page

2.

Who created the first version of PHP?

a)

James Gosling

b)

Brendan Eich

c)

Rasmus Lerdorf

d)

Dennis Ritchie

3.

What symbol do all PHP variables start with?

a)

&

b)

$

c)

@

d)

#

4.

Which of the following is NOT a PHP-supported database?

a)

Oracle

b)

PostgreSQL

c)

Firebase

d)

MySQL

5.

Which tool is used to locally run and test PHP code with Apache and MySQL?

a)

Visual Studio

b)

Java SDK

c)

XAMPP

d)

NetBeans

6.

What is the correct PHP tag to enclose PHP code?

a)

<% %>

b)

<script>..</script>

c)

<?php...?>

d)

<...>

7.

Which function is used to declare a constant in PHP?

a)

const()

b)

constant()

c)

define()

d)

declare()

8.

What PHP operator is used to join strings or variables?

a)

+

b)

&

c)

.

d)

*

9.

What is the purpose of the echo or print statement in PHP?

a)

Store values

b)

Display output

c)

Read files

d)

Encrypt data

10.

What are the prerequisites before learning PHP, aside from HTML, CSS, and JavaScript?

a)

Python and SQL

b)

MySQL and Bootstrap

c)

None required

d)

Basic understanding of front-end development

11.

Which of the following text editors can be used to write PHP code?

a)

Vscode

b)

Photoshop

c)

Excel

d)

Illustrator

12.

Which combination correctly lists the minimum essential components for running and testing a PHP application on your machine?

a)

Web Server, MySQL, FTP Server

b)

XAMPP, Text Editor, Web Browser

c)

Java SDK, Notepad, MySQL

d)

Bootstrap, Node.js, Apache

13.

You need to create a PHP script that reads user input, stores it in a file, and displays the result. Which PHP features are essential to achieve this?

a)

Variable declaration, CSS styling, JavaScript functions

b)

Cookie handling, MySQL integration, FTP

c)

File handling functions, echo or print, form handling

d)

Python script inclusion, database connection, HTML canvas

14.

Why is PHP considered "forgiving" compared to other languages?

a)

It forces strict typing of variables.

b)

It allows undeclared variables to run without error.

c)

It is less secure and more relaxed.

d)

It ignores all syntax errors.

15.

What must be started first in XAMPP to run a PHP file?

a)

MySQL

b)

Tomcat

c)

Apache

d)

FTP

16.

What is the most commonly used PHP output command?

a)

print()

b)

echo

c)

write

d)

say

17.

What file extension is used for PHP files?

a)

.html

b)

.js

c)

.css

d)

.php

18.

What is the correct way to start a PHP tag?

a)

php?>

b)

<?php

c)

{php}

d)

<?>

19.

Where should you save your PHP file in the XAMPP directory to access it in a browser?

a)

C:\xampp\php\bin\

b)

C:\xampp\htdocs\

c)

C:\xampp\mysql\

d)

C:\xampp\control\

20.

Which of the following correctly outputs the text "Hello World" in PHP?

a)

print("Hello World");

b)

echo = "Hello World";

c)

output("Hello World");

d)

display("Hello World");

21.

What is the purpose of the concatenation operator in PHP?

a)

Add numbers

b)

Join strings or variables

c)

End lines

d)

Format data

22.

What operator is used to concatenate strings in PHP?

a)

+

b)

&

c)

. (dot)

d)

,

23.

Which tag style is the most recommended for writing PHP code?

a)

<?php...?>

b)

<?php....>

c)

<% ... %>

d)

<?...?>

24.

What is required to view a PHP file output in the browser?

a)

A compiler

b)

A terminal

c)

A text editor

d)

A web browser

25.

In PHP, which of the following is NOT a correct variable name?

a)

$name1

b)

$Name_2

c)

$3name

d)

$full_name

26.

Which is a correct example of a single-line comment in PHP?

a)

-- comment

b)

# comment

c)

/* comment */

d)

27.

You're asked to display a full name using two variables $first and $last. Which is the correct PHP code?

a)

echo $first + $last;

b)

echo $first . $last;

c)

echo "$first $last";

d)

B and C are both correct

28.

A student writes PHP code but doesn't see the output. What is the MOST LIKELY cause?

a)

File not saved in Notepad

b)

File saved in wrong XAMPP directory

c)

No semicolon in HTML

d)

File has no extension

29.

Why is echo generally preferred over print for output in PHP?

a)

echo is more secure

b)

echo is case-insensitive

c)

echo is slightly faster and can output multiple parameters

d)

echo can read files

30.

What is a conditional statement in PHP used for?

a)

To repeat a set of instructions

b)

To store data

c)

To perform different actions based on conditions

d)

To send emails

31.

Which of the following is the correct syntax for an if statement in PHP?

a)

if condition then { ... }

b)

if (condition) { ... }

c)

if: (condition) { ... }

d)

if -> condition { ... }

32.

What keyword is used to provide an alternative action when an if condition is false?

a)

otherwise

b)

elseif

c)

else

d)

default

33.

How do you write a single-line comment in PHP?

a)

/* comment */

b)

c)

# comment

d)

/** comment */

34.

What will the following code output? $age = 18; if ($age >= 18) { echo "Adult"; } else { echo "Minor"; }

a)

Error

b)

B. Minor

c)

C. Adult

d)

D. 18

35.

What will this code display? $score = 75; if ($score > 90) { echo "Excellent"; } elseif ($score > 70) { echo "Good"; } else { echo "Needs Improvement"; }

a)

Excellent

b)

Good

c)

Needs Improvement

d)

Error

36.

Choose the correct code that checks if a variable $x is equal to 10.

a)

if $x == 10 then

b)

if $x = 10

c)

if ($x == 10)

d)

if x equals 10

37.

In the code below, what will be the output? $number = 0; if ($number) { echo "True"; } else { echo "False"; }

a)

True

b)

False

c)

0

d)

Error

38.

What does this PHP code do? $loggedIn = true; if ($loggedIn != true) { echo "Please login."; } else { echo "Welcome!"; }

a)

Always prints "Please login."

b)

Always prints "Welcome!"

c)

Displays nothing

d)

Causes an error

39.

What is the best reason to use if...elseif...else structure in PHP?

a)

It makes the code look longer.

b)

It allows checking multiple conditions sequentially.

c)

It always runs faster.

d)

It prevents syntax errors.

40.

Which of the following scenarios best illustrates the use of nested if statements?

a)

Displaying a welcome message

b)

Showing a default price

c)

Checking if a user is logged in and is also an admin

d)

Declaring a variable