PHP Interview Questions and Answers For Freshers

In this post, I am going to provided the significant PHP interview questions and answers for freshers who will be going for a job interview as a PHP developer or want to start career as PHP Developer. These PHP interview questions have been designed specially for freshers to get you familiar with the nature of questions you may face during your interview for the subject of PHP Programming Language.

It will help you to prepare for technical interviews and online selection tests conducted during campus placement for freshers and job interviews for professionals.


1) What is PHP?

Ans:-  PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and CMS for creating websites. PHP is an acronym for “PHP: Hypertext Preprocessor.” It allows the developers to develop dynamic web applications.

2) Who is the father of PHP ?

Ans:-  Rasmus Lerdorf is known as the father of PHP.

3) What is the PHP scripting engine called?

Ans:-  PHP is powered by the scripting engine Zend Engine 2.

4) What types of loops exist in PHP?

Ans:- for, while, do while and foreach.

5) What is the main difference between PHP4 and PHP5?

Ans:- PHP4 uses Zend Engine 1 and doesn’t support the OOPs concept, while PHP5 supports the OOPs concept and uses Zend Engine 2.

6) Is PHP a case sensitive language?

Ans:- Not fully. PHP is partly a case sensitive language where the variable names are case-sensitive but function names are not. Also, user-defined functions aren’t case sensitive but the rest of the language is.

7) What’s the difference between include and require?

Ans:- If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

8) How to create a MySQL connection?

Ans:- mysql_connect(servername,username,password);

9) What are the popular frameworks in PHP?

Ans:- Some popular PHP frameworks are:

  • Laravel
  • CodeIgnitor
  • CakePhp
  • Symfony
  • Zend Framework
  • Yii2

10) Name the popular Content Management Systems (CMS) in PHP.

  • WordPress
  • Joomla
  • Magento
  • Drupa

11) What is NULL?

Ans:- NULL is a particular type which contains only one value: NULL. If you need any variable to set NULL, just assign it.

12) What are ‘Traits’?

Ans:- A mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported is called Traits. It’s not possible to instantiate it on its own.

13) Does PHP support multiple inheritances?

Ans:- PHP supports only single level of inheritance. A class can be inherited from a single class using the keyword ‘extended.’

14) How can we get the browser properties using PHP?



15) What Is a Session?

Ans:- A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests. Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

16) What is the difference between explode() and split() functions?

Ans:- Split function splits a string into array by regular expression. Explode splits a string into array by string.

17) Name and define the three scope levels available in PHP.


Private – Detectable only in its own class
Public – Can be seen by any other code accessing the class
Protected – Can be seen by classes parent(s) and classes that extend the current class

18) How can we register the variables into a session?


19) What is the difference between mysql_fetch_array() and mysql_fetch_assoc() ?

Ans:- mysql_fetch_assoc function Fetch a result row as an associative array, Whilemysql_fetch_array() fetches an associative array, a numeric array, or both

20) How can we create a database using php?

Ans:- mysql_create_db();

21) What are the different types of errors in PHP?

Ans:- There are 4 basically types of error in PHP.

Parse Error – Commonly caused due to syntax mistakes in codes.

Fatal Error – These are basically runtime errors which are caused when you try to access what cannot be done.

Warning Error – This error occurs when you try to include a file that is not present.

Notice Error – This error occurs when you try to utilize a variable that has not been declared.

22) What is the use of “ksort” in php?

Ans:- It is used for sort an array by key in reverse order.

23) What is cookie and why do we use it?

Ans:- A cookie is a small piece of information stored in a client browser. It is a technique utilized to identify a user using the information stored in their browser. Utilizing PHP, we can both set and get COOKIE.

24) What is the difference between $var and $$var?

Ans:- They are both variables. But $var is a variable with a fixed name. $$var is a variable who’s name is stored in $var. For example, if $var contains “message”, $$var is the same as $message.

25) How can we modify the value of a constant?

Ans:- We cannot alter the value of a constant.

26) What are encryption functions in PHP?

Ans:- CRYPT(),MD5()

27) What is Constructors and Destructors?

CONSTRUCTOR : PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.

28) What is the difference between ID and class in CSS?

Ans:- The difference between an ID and Class is that an ID can be utilized to identify one element, whereas a class can be used to identify more than one.

29) What is use of header() function in php ?

Ans:- The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen.

30) What is AJAX?

Ans:- AJAX (Asynchronous JavaScript and XML) is a technique which enables updating parts of a web page, without reloading the entire page. Data is exchanged asynchronously in a small amount of data with the server.

31) How do you pass a variable by value in PHP?

Ans:- Just like in C++, put an ampersand in front of it, like $a = &$b;

32) What is jQuery?

Ans:- jQuery is a fast, small, and feature-rich JavaScript library. It is an easy-to-use API. It makes things like HTML document traversal and manipulation, animation, event handling and Ajax much simpler across a more number of browsers.

33) How do you call a constructor for a parent class?

Ans:- parent::constructor($value)

34) What is JOIN in MySQL? What are the different types of join?

Ans:- MySQL JOINS are utilized to retrieve data from multiple tables. It is performed whenever two or more tables are joined in a SQL statement. There are various types of MySQL joins: INNER JOIN, LEFT JOIN, RIGHT JOIN and OUTER JOIN.

35) What is the difference between the functions unlink and unset?


unlink() deletes the given file from the file system.
unset() makes a variable undefined.

36) How to declare an array in PHP?

Ans:- Ex: var $arr = array(‘apple’, ‘grape’, ‘lemon’);

37) What are default session time and path?

Ans:- default session time in PHP is 1440 seconds or 24 minutes
Default session save path id temporary folder /tmp

38) What is SQL injection?

Ans:- SQL injection is a malicious code injection technique that might destroy your database. It exploiting SQL vulnerabilities in Web applications. It is one of the most common web hacking techniques.

39) How can we find the number of rows in a result set using PHP?


$result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;

40) How to submit a form with a dedicated button in PHP?

Ans:- The document.form.submit() function helps to submit the form. For example: <input type=button value=”SUBMIT” onClick=”document.form.submit()”>

41) How do you verify if a provided variable is empty?

Ans:- I can verify if a given variable is empty by using empty() function.

42) How can you verify the value of a provided variable is a number?

Ans:- I can use is_numeric() function to verify whether it is a number or not.

43) Explain which function provides us the number of modified entries by a query?

Ans:- The function mysql_affected_rows() returns the number of entries modified by an SQL query.

44) What is $_ENV?

Ans:- In PHP, $_ENV is used to return the environment variables from the web server. It is an associative array of variables sent to the latest PHP script through the environment method. To set real environment variables, you need to use putenv().

45) What is $GLOBALS?

Ans:- The $GLOBALS is a PHP superglobal variable. It can be utilized instead of a global keyword to access variables from global scope.

46) Explain how to initiate a session in PHP?

Ans:- session_start() function allows us to activating a session.

47) What is $_FILES?

Ans:- The $_FILES is an associative array created for items sent to the current script through the HTTP POST method

48) What is jQuery.noConflict?

Ans:- jQuery no-conflict is an option given by jQuery to overcome the conflicts between the different javascript frameworks or libraries. When you use jQuery no-conflict mode, you replace the $ to a new variable and assign jQuery some other JavaScript libraries. Also, the $ is used as a function or variable name that jQuery has.

49) What is array_merge ?

Ans:- array_merge function is used to merge array for example


50) How to check whether an array is empty or not?



Leave a Comment