PHP Interview Questions (Beginner Level) – Short Answers
🔹 PHP Interview Questions (Beginner Level) – Short Answers
-
What is PHP?
→ PHP is a server-side scripting language used to create dynamic websites. -
When and why is it used?
→ Used for web development to handle forms, sessions, databases, and more. -
What are the main features of PHP?
→ Open-source, server-side, platform-independent, supports databases. -
Difference between
echo
andprint
?
→echo
is faster and can print multiple values;print
returns 1 (used in expressions). -
How do you declare variables in PHP?
→ With$
symbol. Example:$name = "John";
-
What are data types in PHP?
→ String, Integer, Float, Boolean, Array, Object, NULL. -
Difference between
==
and===
?
→==
compares values,===
compares value + data type. -
What are superglobals?
→ Built-in global variables like$_GET
,$_POST
,$_SESSION
, etc. -
How does PHP handle forms (GET vs POST)?
→$_GET
shows data in URL;$_POST
hides data. POST is safer for sensitive data. -
Difference between
include
andrequire
?
→ Both include files.require
stops script on error,include
gives warning. -
What is the use of
isset()
andempty()
?
→isset()
checks if variable is set.empty()
checks if it's empty. -
Difference between single (
'
) and double ("
) quotes?
→'text'
prints as-is."text $var"
allows variable parsing. -
How to define a constant?
→define("SITE_NAME", "MyWebsite");
-
Different types of arrays?
→ Indexed, Associative, and Multidimensional. -
Indexed vs Associative arrays?
→ Indexed uses numbers ($arr[0]
), associative uses keys ($arr["name"]
). -
How to loop through an array?
→ Useforeach($arr as $item)
orfor
loop. -
Types of loops in PHP?
→for
,while
,do...while
,foreach
. -
How to define a function in PHP?
→function sayHello() { echo "Hello"; }
-
How to handle errors in PHP?
→ Useerror_reporting()
,try-catch
,die()
, orset_error_handler()
. -
How to start a session in PHP?
→session_start();
-
Difference between cookies and sessions?
→ Cookies are stored in browser; sessions are stored on server (more secure).
Comments
Post a Comment