35 Important interview questions with answers for php freshers

by  
Share:
35 Important interview questions with answers for php freshers

In this tutorial I have given the common 35 Important interview questions with answers for php freshers who will going for a job interview as junior PHP developer/ programmer. Topics included are PHP, MySQL, JavaScript, html, CSS, jQuery.

What is PHP?

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

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.

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.

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.

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.

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.

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.

How to print current date and time.

<?php echo date('Y-m-d H:i:s'); ?>

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.

How can we change the value of a constant?

We cannot change the value of a constant.

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.

How do we get the current session ID?

<?php
session_start(); 
echo session_id(); 
?>

How do we destroy a session.
<?php session_start();  session_destroy(); ?>

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.

What is an associative array?

Associative arrays are arrays that use named keys that you assign to them.

<?php
$capitals=array("India"=>"New Delhi","China"=>"Beijing","Pakistan"=>"Islamabad"); 
?>

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.

What is the difference between javascript and PHP?

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

What is CSS?

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

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.

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

document.getElementById("formID").submit();
document.formname.submit();

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.

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.

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.

How can we show and hide an element via jquery?

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

// show div
$('#div1').show();
// hide div
$('#div1').hide();

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.

$('#div1').css('font-size', '18px');

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.

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.

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.

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.

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.

What do we use to remove duplicate records while fetching a data in mysql ?

We use DISTINCT keyword.

What is the use of count function in mysql?

count() is used for fetching the total number records in a table.

How do we use % when performing a search query?

Suppose take an example where you need to fetch all customer data where name stats with sa

SELECT * FROM Customers WHERE name LIKE ‘sa%’;

Another case is where you need to fetch all customer data where kumar is found irrespective of the position (middle name or last name).

SELECT * FROM Customers WHERE name LIKE ‘%kumar%’;

How do we delete a row in a table?

Take an example

DELETE FROM customer WHERE cid=150;

In this case it will delete the record of the customer with customer id 150

How do we drop a table?

DROP table customers;

It will drop the table customers

Get the latest updates directly in your inbox for FREE: Subscribe here

Share your feedback / let me know your doubts regarding this tutorial in the comment box given below.

Share:
Hasan

Shahrukh Khan (Hasan)

A software engineer who's a die-hard coder, blogger, dreamer and mentor with years of expertise in web development. Know more...

Tanjina on

Thanks for sharing, it is really helpful.

Reply
Raham Sher on

…its nice work…

Reply
Shahrukh Khan on

Thank You.

Reply
Avinash Wadhawan on

Nice one.. Gives a bit of information..

Reply
anjana on

nice work

Reply
anjana on

nice one

Reply
Nagesh on

Thank you…

Reply
Gopal Sharma on

Hi…Shahrukh Khan…
This site is very helpfull for the biggners….Continue posting your Questions and Answers …Its Nice

Reply
Santosh Iyengar on

Hats off to you Shahrukh khan, what a brilliant collection of questions!
I’mre its enough for php developer like us

Reply
Roja Dhanasekaran on

thanks..its very useful

Reply
Musharraf Choudhary on

Thanks for sharing…

Reply
Kaushik makwana on

Suprb . . .but i have an question .how give diffrent name for session?

Reply
jayarani on

thank u its really help full

Reply
nipple on

Good way of explaining, and good post to get data regarding my presentation topic,
which i am going to present in school.

Reply
preeti sharma on

nice material.but you should also include some programming questions.

Reply
Shahrukh Khan on

Thanks. will try to update.

Reply
Bhaskar Bhatt on

Hi,
It was really great article for php most important interview questions and answers for freshers.

You can find out more technical questions & answers at http://guruquest.net/

Reply
aarti on

this is realy helpfull for fresher…thank yoy so much,,,

Reply
NJPR on

Nice info and it is useful.

Reply
Bart on

Nice list of php questions. cheers ! and keep up the good work.

Reply
kalyani on

how to prepare can you send me mai.easy wayl

Reply
Zameer on

Nice done, Thank’s !

Reply
Zoya on

Good post.

Reply
Shahrukh Khan on

thanks.

Reply
Jessica on

These are really very useful and important job interview questions and answers for PHP Freshers. This list of job interview questions with answers can surely be helpful for PHP Freshers in getting a new job. Great sharing.

Reply
Shahrukh Khan on

thanks a lot.

Reply
Sneha on

Great… Thankz

Reply
mayank on

thanks shahrukh it gives me alot of knowledge

Reply
arpita on

it is very useful for fresher

Reply
indiainfo on

Hi,
Thanks for sharing the questions with answers and it is really helpful to the job seekers and you can get many php related jobs in peeljobs.com
https://peeljobs.com/

Reply
Aniruddha on

Thank you very much for posting that types of questions and answers . I think it will help us for getting Job ….. Many many thanks a lot

Reply
Shahrukh Khan on

Thanks

Reply
loveleen on

hii sharukh khan tommorow my interview can u hep me by email

ASHISH SRIVASTAVA on

Nice Work……

Reply
Mamun Sabuj on

Nice post for interview questions

Reply
chowdary bhgavan on

THANK U SO MUCH ….IT WILL DEFENTLY USEFUL FOR FRESHERS

Reply
loveleen on

hii shahrukh khan tommorow my interview can you help me on email

Reply
Shahrukh Khan on

what can I do?

Reply
datta on

ok what may ni help u

Reply
ranjith on

that’s really helpfull mine career

Reply
Mahesh Patel on

Very Nice Post..!! It was very Helpful bro.
Thanks For Share…:)
Regard
Mahesh

Reply
suma on

Wow..its so super…it is very helpfull to me

Reply
Pabitra Pradhan on

very nice question

Reply
sabith on

Super bro…

Reply
anju on

nice…

Reply
sithanantham on

Hi Shahrukh Khan,
its very uesful for me…..

Reply
Shahrukh Khan on

Glad it helped

Reply
karthikkumar on

this site is really useful for me so thanks

Reply
Shahrukh Khan on

you are welcome

Reply
rinku on

hi..
tomorrow tommorow my interview please help me on email

Reply
Dipan karmakar on

Hi…shahrukh khan . I want some modern question answer on php for my upcoming interview..plz bro help me to send the question answer by my mail Id.

Reply
Shahrukh Khan on

I will try to post soon.

Reply
vishal on

thanks for this sir

Reply
saurabh on

that sharing bar of facebook, twitter, print , message,pininterest makes left side stuff blocked , please correct it

Reply
Shahrukh Khan on

hi. in which device is that a problem?

Reply
nidhi on

I have faced a number of difficult interview questions like what is your career goal etc. Some of these questions require prior preparation. This blog from you helped me in preparing answers for such questions, with the help of tips shared. Thank you so much

Reply
Shahrukh Khan on

You are welcome, and best of luck!

Reply
Algrim.co on

Some questions you could ask the interviewer, if you DARE…

Why should I work for you,and not a competitor?

How would you describe your job in one word?

How would you sell this role to me?

Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.