Interview Questions

PHP Interview Questions And Answers

PHP Interview Questions And Answers
Written by bakair

PHP Interview Questions And Answers


Welcome . In this part, we are giving you remarkable commonly asked PHP Interview Questions that will assist you to overcome interview session simply. Applicants need to read this part, Then by heart the questions and answers. Also, study sample answers and directions about how to answer these regular interview questions. PHP is an essential component of the web experience, and every web developer should have the essential expertise in PHP.Simple PHP interview questions, that should assist you become a skilled PHP coder. We wish you find these questions helpful. If you are an interviewer, Take the time to read the basic interview subjects you will possibly be asked.


1.What is PHP?

answer:PHP is a server-side scripting language generally used for web applications. PHP has several structures and cms for designing websites.Even a nontechnical person can design sites using its CMS.WordPress,osCommerce are the popular CMS of PHP.It is including an object oriented programming language similar java, C-sharp etc.It is very easy for studying


2.What is the advantage of “echo” in PHP?

answer:It is used to print a data in the web page, Example: <?PHP echo ‘Car security’; ?>, The following code prints the document in the webpage


3.How to add a file to a PHP page?

answer:We can add a file using “include() ” or “require()” function with file path.


 4.What’s the distinction between require  and include?

answer:If the file is not seen by requiring(), it will cause a serious error and stop the performance of the script. If the file is not found by including(), a notification will be issued, but performance will continue.


5.require_once(), require(), include().What is a variation between them?

answer:require() inserts and assesses a particular file, while require_once() does that solely if it has not been added before (on the same page). So, require_once() is suggested to apply when you need to add a file where you have a lot of functions for a case. This way you make certain you don’t include the file many times and you will not get the “function re-declared” error.


6.Differences between GET and POST methods?

answer:We can transfer 1024 bytes using GET system but POST system can transfer a huge amount of data and POST is the protected method than GET method.


7.How to declare an array in PHP?

answer:Eg : var $arr = array(‘apple’, ‘grape’, ‘lemon’);


8.What is the use of ‘print’ in PHP?

answer:This is not truly a real function, It is a language form. So you can use without enclosures with its argument list.

Example print(‘PHP Interview questions’);

print ‘Job Interview ‘);


9.What is value of in_array() function in PHP ?

answer:in_array used to tests if a value exists in an array


10.What is the use of a count() function in PHP?

answer:count() is used to count all components in an array or anything in an object


11.What’s the difference between require and include?

answer:It’s how they manage crashes. If the file is not found by require  (), it will create a fatal error and stop the execution of the script. If the file is not found by include(), a notification will be announced, but execution will continue.


12.What is the distinction between Cookie and Session?

answer:The foremost distinction between sessions and cookies is that sessions are saved on the server, and cookies are saved on the user’s PC in the text file form. Cookies can not hold multiple variables, But Session can hold various variables.We can set an expiry for a cookie, The session only still active as long as the browser is open.Users do not have access to the data you saved in Session Since it is stored in the server.Session is basically used for login/logout while cookies using for user tracking


13.How to place cookies in PHP?

answer:Setcookie(“sample”, “ram”, time()+3600);


14.How to Retrieve a Cookie Value?

answer:eg : echo $_COOKIE[“user”];


15.How to make a session? How to place a value in session? How to Remove data from a session?

answer:make session : session_start();

Set value to session : $_SESSION[‘USER_ID’]=1;

Remove data from session : unset($_SESSION[‘USER_ID’];


16.what kinds of loops are in PHP?

answer:for, while,do-while and for each (NB: You must learn its usage)


17.How to make a MySQL connection?



18.How to select a database?



19.How to execute an sql query? How to fetch its result ?

answer:$my_qry = mysql_query(“SELECT * FROM `users` WHERE `u_id`=’1′; “);

$result = mysql_fetch_array($my_qry);

echo $result[‘First_name’];


20.Write a program by while loop

answer:$my_qry = mysql_query(“SELECT * FROM `users` WHERE `u_id`=’1′; “);

while($result = mysql_fetch_array($my_qry))


echo $result[‘First_name’.].”<br/>”;



21.How we can retrieve the data in the result set of MySQL using PHP?

answer:1. mysql_fetch_row

  1. mysql_fetch_array
  2. mysql_fetch_object
  3. mysql_fetch_assoc


22.What is the usage  of explode() function ?

answer:Syntax : array explode ( string $delimiter , string $string [, int $limit ] );

This function separates a string into an array. All of the array elements is a substring of a sequence formed by breaking it on boundaries formed by the string delimiter.


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

answer:Split function splits sequence into an array by regular expression. Explode splits a string into array by string.


24.What is the use of mysql_real_escape_string() function?

answer:It is used to escapes special characters in a string for use in an SQL statement


25.Write down the code for save an uploaded file in php.

if ($_FILES[“file”][“error”] == 0)


“upload/” . $_FILES[“file”][“name”]);

echo “Stored in: ” . “upload/” . $_FILES[“file”][“name”];



26.How to create a text file in php?

answer:$filename = “/home/user/guest/newfile.txt”;

$file = fopen( $filename, “w” );

if( $file == false )


echo ( “Error in opening new file” ); exit();


fwrite( $file, “This is a simple test\n” );

fclose( $file );


27.How to remove whitespace (or other characters) from the beginning and end of a string?

answer:The trim() function removes whitespaces or other predefined characters from both sides of a string.


28.What is the use of a header() function in PHP?

answer:The header() function sends a raw HTTP header to a client browser.donot forget that this function must be called before sending the exact output.For example, You do not print any HTML element before using this function.

About the author


Leave a Comment