WorksheetsPHP Preliminary Examination
Total questions: 40
Worksheet time: 20mins
What does PHP stand for?
Programming Hypertext Page
Preprocessor Hyperlink Page
PHP: Hypertext Preprocessor
Personal Home Page
Who created the first version of PHP?
James Gosling
Brendan Eich
Rasmus Lerdorf
Dennis Ritchie
What symbol do all PHP variables start with?
&
$
@
#
Which of the following is NOT a PHP-supported database?
Oracle
PostgreSQL
Firebase
MySQL
Which tool is used to locally run and test PHP code with Apache and MySQL?
Visual Studio
Java SDK
XAMPP
NetBeans
What is the correct PHP tag to enclose PHP code?
<% %>
<script>..</script>
<?php...?>
<...>
Which function is used to declare a constant in PHP?
const()
constant()
define()
declare()
What PHP operator is used to join strings or variables?
+
&
.
*
What is the purpose of the echo or print statement in PHP?
Store values
Display output
Read files
Encrypt data
What are the prerequisites before learning PHP, aside from HTML, CSS, and JavaScript?
Python and SQL
MySQL and Bootstrap
None required
Basic understanding of front-end development
Which of the following text editors can be used to write PHP code?
Vscode
Photoshop
Excel
Illustrator
Which combination correctly lists the minimum essential components for running and testing a PHP application on your machine?
Web Server, MySQL, FTP Server
XAMPP, Text Editor, Web Browser
Java SDK, Notepad, MySQL
Bootstrap, Node.js, Apache
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?
Variable declaration, CSS styling, JavaScript functions
Cookie handling, MySQL integration, FTP
File handling functions, echo or print, form handling
Python script inclusion, database connection, HTML canvas
Why is PHP considered "forgiving" compared to other languages?
It forces strict typing of variables.
It allows undeclared variables to run without error.
It is less secure and more relaxed.
It ignores all syntax errors.
What must be started first in XAMPP to run a PHP file?
MySQL
Tomcat
Apache
FTP
What is the most commonly used PHP output command?
print()
echo
write
say
What file extension is used for PHP files?
.html
.js
.css
.php
What is the correct way to start a PHP tag?
php?>
<?php
{php}
<?>
Where should you save your PHP file in the XAMPP directory to access it in a browser?
C:\xampp\php\bin\
C:\xampp\htdocs\
C:\xampp\mysql\
C:\xampp\control\
Which of the following correctly outputs the text "Hello World" in PHP?
print("Hello World");
echo = "Hello World";
output("Hello World");
display("Hello World");
What is the purpose of the concatenation operator in PHP?
Add numbers
Join strings or variables
End lines
Format data
What operator is used to concatenate strings in PHP?
+
&
. (dot)
,
Which tag style is the most recommended for writing PHP code?
<?php...?>
<?php....>
<% ... %>
<?...?>
What is required to view a PHP file output in the browser?
A compiler
A terminal
A text editor
A web browser
In PHP, which of the following is NOT a correct variable name?
$name1
$Name_2
$3name
$full_name
Which is a correct example of a single-line comment in PHP?
-- comment
# comment
/* comment */
You're asked to display a full name using two variables $first and $last. Which is the correct PHP code?
echo $first + $last;
echo $first . $last;
echo "$first $last";
B and C are both correct
A student writes PHP code but doesn't see the output. What is the MOST LIKELY cause?
File not saved in Notepad
File saved in wrong XAMPP directory
No semicolon in HTML
File has no extension
Why is echo generally preferred over print for output in PHP?
echo is more secure
echo is case-insensitive
echo is slightly faster and can output multiple parameters
echo can read files
What is a conditional statement in PHP used for?
To repeat a set of instructions
To store data
To perform different actions based on conditions
To send emails
Which of the following is the correct syntax for an if statement in PHP?
if condition then { ... }
if (condition) { ... }
if: (condition) { ... }
if -> condition { ... }
What keyword is used to provide an alternative action when an if condition is false?
otherwise
elseif
else
default
How do you write a single-line comment in PHP?
/* comment */
# comment
/** comment */
What will the following code output? $age = 18; if ($age >= 18) { echo "Adult"; } else { echo "Minor"; }
Error
B. Minor
C. Adult
D. 18
What will this code display? $score = 75; if ($score > 90) { echo "Excellent"; } elseif ($score > 70) { echo "Good"; } else { echo "Needs Improvement"; }
Excellent
Good
Needs Improvement
Error
Choose the correct code that checks if a variable $x is equal to 10.
if $x == 10 then
if $x = 10
if ($x == 10)
if x equals 10
In the code below, what will be the output? $number = 0; if ($number) { echo "True"; } else { echo "False"; }
True
False
0
Error
What does this PHP code do? $loggedIn = true; if ($loggedIn != true) { echo "Please login."; } else { echo "Welcome!"; }
Always prints "Please login."
Always prints "Welcome!"
Displays nothing
Causes an error
What is the best reason to use if...elseif...else structure in PHP?
It makes the code look longer.
It allows checking multiple conditions sequentially.
It always runs faster.
It prevents syntax errors.
Which of the following scenarios best illustrates the use of nested if statements?
Displaying a welcome message
Showing a default price
Checking if a user is logged in and is also an admin
Declaring a variable
