Skip to content

PHP Tutorial PHP Interview and Practice

Beginner PHP Interview Questions

Lesson 358 of 369 4 min read By Deepak Paswan Updated Oct 5, 2026

Interviewers for junior roles check that you understand the basics and can explain them simply. Practise answering out loud, in your own words. Short, correct answers with a small example are best.

Q1. What is PHP?

PHP is a server-side scripting language for web development. The server runs the PHP code and sends the resulting HTML to the browser. It is open source, runs on most hosting, and powers WordPress, Laravel and many other systems.

Q2. What is the difference between server-side and client-side code?

Server-side code (PHP) runs on the server, can access databases and secrets, and the visitor never sees the code. Client-side code (HTML, CSS, JavaScript) runs in the browser and can be read and changed by the visitor. So anything that must be trusted (validation, permissions, prices) must be checked on the server.

Q3. How do you start and end PHP code?

With <?php and (optionally) ?>. In a file that contains only PHP, leave out the closing tag, so no stray whitespace is sent. <?= $x ?> is the short echo tag.

Q4. What is the difference between echo and print?

Both output text. echo can take several comma-separated values and returns nothing. print takes one value and returns 1. In practice, use echo.

index.php
PHP
<?php
echo "a", "b", "\n";
$r = print "c\n";
echo $r;
Output
OUTPUT
ab
c
1

Q5. How do you declare a variable and a constant?

Variables start with $ ($name = "Ana";). Constants are created with const NAME = 1; or define("NAME", 1); and have no $. A constant cannot be changed after it is set.

Q6. Are PHP variable names case-sensitive?

Variable names, constants and array keys are case-sensitive. Function names, class names and keywords are not.

Q7. What is the difference between == and ===?

== compares values after type conversion. === compares value and type. Use === by default.

index.php
PHP
<?php
var_dump("0" == false);
var_dump("0" === false);
var_dump(0 == "a");
Output
OUTPUT
bool(true)
bool(false)
bool(false)

In PHP 8, 0 == "a" is false (it was true in PHP 7).

Q8. What is the difference between include and require?

If the file is missing, include gives a warning and continues, while require gives a fatal error and stops. The _once versions load a file only once. Use require_once for files with functions and classes.

Q9. What is the difference between GET and POST?

GET sends data in the URL (visible, bookmarkable, size-limited) and should only read. POST sends data in the request body and is used to change data. POST is not “secure” by itself: use HTTPS, and validate all input.

Q10. How do you read form data?

From $_GET and $_POST. Always read with a default ($_POST["name"] ?? ""), trim and validate, and escape when printing back with htmlspecialchars().

Q11. What are sessions and cookies?

A cookie is a small piece of data stored in the browser and sent with every request. A session stores data on the server, and the browser keeps only a session ID in a cookie. Use sessions for anything private, like login state.

Q12. What does isset() do, and how is it different from empty()?

isset($x) is true if the variable exists and is not null. empty($x) is true for a missing variable or a falsy value (0, "0", "", null, false, []). Be careful: empty("0") is true.

Q13. What is the null coalescing operator?

$a ?? $b returns $a if it exists and is not null, otherwise $b. It never raises a warning for a missing variable or key.

index.php
PHP
<?php
$user = ["name" => "Ana"];

echo $user["email"] ?? "no email";
Output
OUTPUT
no email

Q14. How do you connect PHP to a database safely?

With PDO and prepared statements. Placeholders keep data separate from SQL, which prevents SQL injection.

Q15. How would you check which PHP version is running?

php -v on the command line, or PHP_VERSION and phpversion() in code. Use version_compare() for comparisons.

index.php
PHP
<?php
var_dump(version_compare(PHP_VERSION, "8.0.0", ">="));
Output
OUTPUT
bool(true)

How to practise

  • Say each answer aloud in 30 seconds.
  • Add a tiny example from your own projects.
  • Run the code on this page, then change it and predict the new output.
lightbulb
Admit what you do not know
“I have not used that, but I would look at the manual for it, and I would expect it to…” is a good answer. Guessing confidently and being wrong is a worse one.