PHP Interview Questions

Basic PHP Questions
-
What is PHP?
-
What does PHP stand for?
-
What are the main features of PHP?
-
What is a PHP variable?
-
How do you declare a variable in PHP?
-
What are data types in PHP?
-
What is the difference between
echo
andprint
? -
How do you write comments in PHP?
-
What are constants in PHP?
-
How do you define a constant?
-
What is a PHP array?
-
What are the types of arrays in PHP?
-
How to create an associative array?
-
What is the use of
isset()
function? -
What is the use of
empty()
function? -
What is the difference between
==
and===
? -
What is a function in PHP?
-
How do you declare a function in PHP?
-
What is the scope of variables in PHP?
-
What is recursion?
Control Structures
-
What is an
if
statement? -
How do you write an
if-else
condition? -
What is a
switch
statement? -
What is a loop in PHP?
-
What is a
for
loop? -
What is a
while
loop? -
What is a
do-while
loop? -
How do you stop a loop early?
-
What is the
continue
keyword used for? -
How to loop through an array?
String & Array Functions
-
How do you find the length of a string?
-
How do you convert a string to lowercase?
-
What is
explode()
in PHP? -
What is
implode()
in PHP? -
How do you sort an array?
-
How do you reverse an array?
-
How to find a value in an array?
-
What is the use of
in_array()
? -
How do you merge two arrays?
-
What is the difference between
array_merge()
and+
operator?
Forms & User Input
-
How do you create a form in PHP?
-
What are
GET
andPOST
methods? -
What is the difference between
GET
andPOST
? -
How do you access form data in PHP?
-
How do you validate form data in PHP?
-
How do you prevent XSS in form data?
-
How to sanitize user input?
-
How to upload a file using PHP?
-
What is
$_FILES
? -
How do you handle file upload errors?
Sessions & Cookies
-
What is a session in PHP?
-
How to start a session in PHP?
-
How do you store data in a session?
-
How do you destroy a session?
-
What is a cookie?
-
How do you create a cookie in PHP?
-
How do you read a cookie in PHP?
-
What is the difference between sessions and cookies?
-
What are the security concerns with sessions?
-
How to set cookie expiry time?
File Handling
-
How do you read a file in PHP?
-
How do you write to a file in PHP?
-
What is
fopen()
function? -
What is the use of
fclose()
? -
How do you check if a file exists?
-
What is the difference between
file_get_contents()
andfread()
? -
What is the use of
unlink()
function? -
What are file modes like
r
,w
,a
?
Error Handling
-
How do you handle errors in PHP?
-
What is
try-catch
block in PHP? -
What is the difference between warning and error?
-
What is a notice in PHP?
-
What is the use of
error_reporting()
? -
How to log errors in a file?
OOP in PHP
-
What is Object-Oriented Programming (OOP)?
-
What is a class in PHP?
-
What is an object?
-
What is the
__construct()
function? -
What is inheritance in PHP?
-
What is method overloading?
-
What are access modifiers:
public
,private
,protected
? -
What is the difference between
static
and non-static methods? -
What is an abstract class?
-
What is an interface?
MySQL with PHP
-
How do you connect PHP with MySQL?
-
What is
mysqli_connect()
? -
How do you run a query in PHP?
-
How to insert data into MySQL using PHP?
-
How to fetch data from MySQL using PHP?
-
What is SQL injection?
-
How do you prevent SQL injection?
-
What is PDO in PHP?
-
What is the difference between
mysqli
andPDO
? -
How do you handle database errors?
Advanced & Miscellaneous
-
What is Composer in PHP?
-
What are traits in PHP?
-
What are magic methods in PHP?
-
What is
autoload
in PHP? -
What is the difference between include and require?
-
What is the use of
namespace
in PHP?