Thursday , April 18 2019
Home / Tips / PHP / 30 Basic Interview Questions in PHP

30 Basic Interview Questions in PHP

30 Important interview questions with answers for php freshers

1.What is PHP?

PHP is an open source server side scripting language commonly used for web applications.

2.What is Open Source Software?

Software in which the source codes are freely used, modify, and shared by anyone are called Open Source Software. These can also be distributed under licenses that adhere with the Open Source Definition.

3.What is the difference between include(), include_once() and require_once()?

The include() statement includes and evaluates a specified line i.e. it will include a file based in the given path. require() does the same thing expect upon failure it will generate a fatal error and halt the script whereas include() will just gives a warning and allow script to continue. require_once() will check if the file already has been included and if so it will not include the file again.

4.Differences between GET, POST and REQUEST methods ?

GET and POST are used to send information from client browser to web server. In case of GET the information is send via GET method in name/value pair and is URL encoded. The default GET has a limit of 512 characters. The POST method transfers the information via HTTP Headers. The POST method does not have any restriction in data size to be sent. POST is used for sending data securely and ASCII and binary type’s data. The $_REQUEST contains the content of both $_GET, $_POST and $_COOKIE.

5.What are the different errors in PHP?

There are 4 basically types of error.
Parse Error – Commonly caused due to syntax mistakes in codes e.g. missing semicolon, mismatch brackets.

Fatal Error – These are basically run time errors which are caused when you try to access what can’t be done. E.g. accessing a dead object, or trying to use a function that hasn’t been declared.

Warning Error – These occurs when u try to include a file that is not present, or delete a file that is not on the server. This will not halt the script; it will give the notice and continue with the next line of the script.

Notice Error – These errors occurs when u try to use a variable that hasn’t been declared, this will not halt the script, It will give the notice and continue with the next line of the script.

6.What is session and why do we use it?

Session is a super global variable that preserve data across subsequent pages. Session uniquely defines each user with a session ID, so it helps making customized web application where user tracking is needed.

7.What is cookie and why do we use it?

Cookie is a small piece of information stored in client browser. It is a technique used to identify a user using the information stored in their browser (if already visited that website).Using PHP we can both set and get COOKIE.

8.How to print current date and time?

9.What function do we use to find length of string, and length of array?

For finding length of string we use strlen() function and for array we use count() function.

10.How can we change the value of a constant?

We cannot change the value of a constant.

11.What is the difference between unset() and unlink() function?

unset() is used to destroy a variable where as unlink() is used to destroy a file.

12.How do we get the current session ID?

13.How do we destroy a session?

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

Both are used to split a string to array, the basic difference is that split() uses pattern for splitting and explode() uses a string. explode() is faster than split() as it does not match the string based on regular expression. Also split() is deprecated as of 5.3.0. So using of this function is discouraged.

15.What is an associative array?

16.What is PDO classes?

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. It is a data-access abstraction layer, so no matter what database we use the function to issue queries and fetch data will be same. Using PDO drivers we can connect to database like DB2, Oracle, PostgreSQL etc.

17.What is the difference between javascript and PHP?

Javascript is a client side scripting language whereas PHP is a server side scripting language.

18.What is CSS?

CSS or cascading Style Sheet is a way to style and present HTML.

19.What is the difference between ID and class in CSS?

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

20.How can we submit a form without using submit buttons?

We can use javascript submit function. We can either use form name or form id to print

21.Why do we use multipart/form-data in html form?

This is the encoding used to send image or files via form, The data will be split into multiple parts and, one for each files plus one for the text of the form body that may be sent with them.

22.What is AJAX?

AJAX (Asynchronous JavaScript and XML) is a technique which allows updating parts of a web page, without reloading the whole page. Data is exchanged asynchronously in small amounts of data with the server.

23.What is jQuery?

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

24.How can we show and hide an element via jquery?

Suppose we want to show and hide elements of a div with id div1.

25.How can we add change font size using jquery?

Suppose we want change a font size of and div with id div1 from 12px to 18px.

26.What is the difference between sql and Mysql?

SQL or Structured Query Language is a programming language designed for managing data held in a Relational Database Management System. Mysql is a open source, relational database management System.

27.Why do we use GROUP BY and ORDER BY function in mysql?

Group By is used for retrieving information about a group of data. It is generally used with some aggregate function like SUM, AVG etc. ORDER BY is used to sort the records using column name. It can sort column in both ascending and descending order.

28.What is JOIN in mysql? What are the different types of join?

When we have to fetch records from more than one table we can use JOIN keyword. The process is known as joining the tables. There are various types of join like INNER JOIN, LEFT JOIN, RIGHT JOIN, and OUTER JOIN.

29.Why is the basic difference between LEFT JOIN, RIGHT JOIN and INNER JOIN?

INNER Join compares two tables and only returns results where a match exists. Records from the 1st table are duplicated when they match multiple results in the 2nd. INNER joins tend to make result sets smaller, but because records can be duplicated this isn’t guaranteed.

LEFT join means keep all records from the 1st table no matter what and insert NULL values when the 2nd table doesn’t match.

RIGHT Join means the opposite: keep all records from the 2nd table no matter what and insert NULL values when the 1st table doesn’t match.

30.If we use SUM function in mysql, does it return sum of that row or for that column?

Sum function works on the column basis and will return the sum of that particular row only.

Print Friendly, PDF & Email

Give us your valuable feedback


About Kadiyala