PHP Interview


Introduction

This site provides all the PHP Interview Question For Freshers in a bunch related to each IT subject present at this site. In the current era, when students are looking for a job then the technical questions related to the programming knowledge are asked into the interview to the interview-person. To prepare the technical round of the interview, job seeker has to clear this round by answering these questions. Here all the technical questions are available in the simplest form so that students can understand easily because this site’s purpose is to provide the easy learning at one click. Here all the PHP Developer Interview Questions are available which goes up to basic level to advance level.

We know that PHP is the server side scripting language which is widely used on the web technology. When any web development vacancy is offered by the companies then they should check the knowledge of the server side scripting language mostly it can be PHP. In PHP there are lot of questions are raised when anyone give the interview for the PHP. Here all the possible questions are available. Just users have to visit the eitworld.com to get the better experience.

We know that PHP is widely used server side scripting language in market so it is clear that post for PHP developers are most. But students have to clear the tough phase of interview to get the job to play the role as the PHP developer. Here eitworld.com provides the better solutions to users for Basic PHP Interview Question For Freshers. Here we clear all the doubts using our sharp and simple manner PHP tutorial which make the user and user can feel and get the better experience.

Eitworld.com also covers PHP Interview Questions And Answers For Freshers and the various short question answers type to fulfill the requirement of academics. So that students can take the advantage in their exam to lead the marks. Here eitworld.com provides the each kind of possible ways to connect the students because we provide the education at one click means all the technology related to the IT are present here.

Now Let's see the list of top PHP interview questions.

1.What is PHP?

Answer: PHP is a web development language that is used for developing dynamic web pages.

2. What is the full form of PHP?

Answer: The full form of PHP is Hypertext Preprocessor.

3.Who developed PHP?

Answer: PHP was developed by the Rasmus Lerdorf.

4.Which year PHP language was developed?

Answer: PHP language was developed in 1994.

5.Which extension is used to save the PHP file??

Answer: PHP files have the extension .php, that means if a file is having php code, it must be saved like example.php

6.What is the actually used PHP version?

Answer: PHP version 5 is the actually used version of PHP..

7.What is the use of echo statement in PHP?

Answer: echo statement is used to display output in PHP. For example echo "<br><br>"; this statement will display two line breaks on a PHP web page.

8.What do you mean by variables?

Answer: A variable is a name given to a memory location which stores some data.

9. Write the rules for naming a variable in PHP.

Answer: 1) Each variable name must be started after using a dollar sign ($).

2) The name must be started with an alphabet or an underscore (_).

3) It may contain only alpha- numeric characters and underscores.

4) No space is allowed. Two words can be separated using underscore.

5) Variable names are case- sensitive.

10. Could we start a variable with number like "$2robin" in PHP?

Answer: No, we can not start a variable with number like "$2robin" as A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

11.What is the difference between $var and $$var?

Answer: $var is variable where as $$var is reference variable like $var=website and $$var=eitworld so $website value is eitworld.

12.Write down the features of variable in PHP language?

Answer: 1.There is no syntax for declaring a variable in PHP; therefore there is no need to declare a variable before using it.

2. No datatype is declared for a variable in php. Any variable can contain any type of value.

3. If a variable is used without assigning it a value, it will show an error.

13.Tell me about the scope of variable.

■ The scope is the accessibility of the variables. It tells where a variable can be accessed from. The scope can be of two types-

1.Local- The accessibility of the variable is limited to a particular block or function.

2.Global- The variable can be accessed from anywhere in the document and from any function.

14.Which function is used to create constant in PHP?

Answer: define() function is used to create constant in PHP.

15. Write and explain the syntax of define() function.

Answer: The syntax of define() function is given below:

define(name, value, case-insensitive)
■ Here name specifies the name of the constant.

■ value specifies the value of the constant.

■ case-insensitive specifies whether the constant name should be case-insensitive or not. Its default value is false.

16.How to declare an array in php?

Answer: Following example shows the way to declare an array in PHP:

$arr= array("value1","value2","value2");
17. What is the need of array while you can create as many individual variables as you want?

Answer: Here we are going to explain you the need of array:

■ Suppose if you have 500 values to store for example you want to save a record of students in a school. It will be irritating and almost impossible to create 500 different variables for each detail of the students. Here comes the need of array. You can create a single array and save all the 500 values in it. There are very less variables to handle when we use array.

■ If you want to search for a particular value from many variables, this is not possible while individual variables are there. But in array, you can easily loop through the array to access all the values in it, find your desired value and manipulate it according to your need.

18. How to include a file to a php page??

Answer: We can include a file using "include() " or "require()" function with file path as its parameter.

19.What is the difference between include and require?

Answer: If the file including is executed successfully, there is no difference between include and require. The difference comes in sight when file including is failed.

■ If file including gets failed then:

◉ include gives a warning and compiles rest of the script

◉ whereas require gives a fatal error and stops the script immediately.

■ If you want to continue the script even if a file that is to be included is missing, use include statement.

■ If you are dealing with frameworks or some secured page, use require statement to immediate stop the script if a file is missing. .

20. Which function is used to send email in PHP?

Answer: mail() function is used to send email in PHP.

21.Write and explain the syntax of mail() function.

Answer: Here is the syntax of mail() function:

mail(to, subject, message, additional_headers, additional_parameters);
■ The mail() function contains following parameters-

◉ to= (Required) It is the email address of the receiver.

◉ subject= (Required) It is the subject of the email.

◉ message= (Required) It is the main body of the email.

◉ additional_headers= (Optional) Besides above three things, there are some additional headers like from, cc, bcc etc. They can be specified in this parameter. Different headers are separated using '\r\n'. It will be more clear by the example below.

◉ additional_parameters= (Optional) It specifies some additional parameters as command line argument.

22.Which methods are used for form submitting in PHP?

Answer: Get and Post methods are used for form submitting in PHP.

23. What do you mean by Get and Post methods in PHP?

Answer: In PHP Get & Post methods are used to submit or transfer form data to same or another page. As both of these methods are used to submit or transfer form data but there are lots of difference in their working. In GET method key values are passed in the Url while in POST method, the information transfers in a hidden manner.

24.What do you mean by Session?

Answer: The time between a user started a work and ended the work is called a session. The number of times he repeated this process i.e. starts the work and ends it is the number of sessions. When you start working on server, it may be assumed that a session is started and that particular session ends when you end your work on server.

To count the number of sessions, to store the information that the user changed or modified in that particular time, session variable is used. Session variables can be used to count the page views of a particular page.

25.Which function is used to start a session?

Answer: session_start() function is used to start a session.

26.How can we register the variables into a session?

Answer: The given syntax is used to register the variables into a session:

<?php

session_register($ur_session_var);

?>
27.How can you access the session variable?

Answer: $_SESSION['variableName'] is used to access the session variable.

28.Which function is used to completely finish the session?

Answer: session_destroy() function is used to completely finish the session. As given below:

<?php session_destroy(); ?>
29.What do you mean by PHP Cookie?

Answer: Cookie is a very small file which is used to identify a user. Cookie lets you know if a new user has visited your web page or it was someone who has visited your page before. Server embeds the cookie with the computer of the user who visits the page. Now every time when the same user visits the page, the cookie that has been embedded with his system is retrieved.

30.Which Function is used to create cookie in PHP?

Answer: setCookie() function is used to create a cookie in PHP.

31.Write and explain the syntax of setCookie function?

Answer:The syntax of setCookie() function is given below:

setCookie(name,value,expiry,path,domain,secure,httponly);
■ The setCookie function has following parameters-

◉ name= (Required) It is the name of the cookie.

◉ value= (Required) It is the initialization value of the cookie.

◉ expiry= (Required) It is the time at which the cookie will be expired automatically.

■ It can be set by adding the required duration in the current time. Current time can be obtained using time() function.

◉ path= (Optional) It specifies the path in the website on which the cookie will be available. To make it available on entire domain, use "/"

◉ domain= (Optional) It specifies the domains and the subdomains in which the cookie will be available..

◉ secure= (Optional) It will have two values, either true or false. If it is set to true, the cookie will be set only if a secure connection exists.

◉ httponly= (Optional) It will have two values, either true or false. If it is set to true, the cookie will be accessible only through HTTP protocol.

32. How can you retrieve a cookie in PHP?

Answer: In PHP language a cookie can be retrieved using $_COOKIE['cookieName'].

33.What is the use of PHP strlen() function?

Answer: PHP strlen() function returns the length of string. It tells us how many characters are their in a string. For example echo strlen("www.eitworld.com"); this statement will print length of the string "www.eitworld.com" which is 16.

34.Which PHP function is used to reverse a string?

Answer: PHP strrev() function is used to reverse a string.

35.What should be the output of the statement : echo strrev("Popular Tutorial");?

Answer:The above statement will print the reverse string of string "Popular Tutorial" and reverse string of Second string Popular Tutorial is "lairotuT ralupoP" that's why above statement will print lairotuT ralupoP on the screen.

36.What do you mean by PHP str_word_count() function ?

Answer: PHP str_word_count() function counts the number of words in String. For example echo str_word_count("PHP Tutorial"); this statement will print number of words in the string "PHP Tutorial" which is 2.

37.Tell me about the PHP strpos() function?

Answer: PHP strpos() function search for the required text in a string.If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. For example echo strpos("PHP Tutorial", "PHP"); will print the position of the string "PHP" in the string "PHP Tutorial" which is 0.

38.What is the use of PHP str_replace() function?

Answer:The PHP str_replace() function replaces some characters with some other characters in a string. For example if we want to replace "Tutorial" with "Books" in the string "Popular Tutorial" then we have to use the statement : str_replace("Tutorial", "Books","Popular Tutorial");.

39.What do you mean by Loops?

Answer: Loops are used to execute the same code for a required number of times. They are also called Iterations. The code inside a loop keeps executing till a particular condition is satisfied. As soon as the condition becomes false, the loop is over and the code is transferred to the very next statement after the code of loop.

40.How many loops are their in PHP?

Answer: There are four loops in php-

1.while loop

2.do...while loop

3.for loop

4.foreach loop

41.What does a special set of tags do in PHP?

Answer: The output is displayed directly to the browser.

42.What is MySql?Explain in detail.

Answer: MySQL is a popular database system that was developed and distributed by ORACLE. It is commonly used on the web i.e. it runs on server. It is very much trusted database system. It is suitable for both small and large applications.MySQL basically uses standard SQL.It is much popular because of its simplicity and fast speed and also because of being free of cost.MySQL is named after its co-founder Monty Widenius's daughter: My

43.What do you mean by MySql Queries?

Answer:Queries are a kind of commands or requests which are used to ask the MySQL server to perform some action on the database.

44.How can you stop the execution of a php script ?

Answer: exit() function is used to stop the execution of a page.

45.What do you mean by Indexed Arrays?

Answer: Those arrays which contain numeric index are known as Indexed Arrays.

46.What do you mean by Associative Arrays?

Answer: Those arrays which contain named index are known as Associative Arrays.

47.Which function is used to connect the MySQL server to the php script?

Answer: mysqli_connect() function is used to connect the MySQL server to the php script.

48.Write and explain the syntax of mysqli_connect() function.

Answer: Here is the syntax of mysqli_connect() function:

mysqli_connect("host","username","password","databaseName");
■ mysqli_connect() function contains mainly these parameters-

◉ host- This can be a host name or the IP address. For the server you installed with wamp server, host name will be localhost.

◉ username- This is the username for MySQL server. For our case, it will be root.

◉ password- This is the password for MySQL server. For our case, there is no password set.

◉ databaseName- This is the parameter which will be effective if you want to work with a database that has been created before. You can directly connect to the database which name will be given here. If you want to create a new database, omit this parameter.

49.Which function is used to execute all the queries in MySQL.?

Answer: mysqli_query() function is used to execute all the queries in MySQL. Here is the syntax of mysqli_query() function:

mysqli_query(mysqli_connect(...),"CREATE DATABASE databaseName");
In the above syntax CREATE DATABSE is the statement which is used to create a new database.

50.Which function is used to close the connection between the MySQL server and php script?

Answer: mysqli_close() function is used to close a connection between the MySQL server and php script. It takes a single parameter which is the link of the connection.Here is the syntax of mysqli_close() function:

mysqli_close($connect);


51.Is it possible to destroy a cookie?

Answer: Yes, it is possible by setting the cookie with a past expiration time.

52.Which query is used to insert data in PHP?

Answer: Insert Into query is used to insert data into PHP database table. It would be more precise to say that this query is used to add new records in the database table..

53.Who is known as the father of PHP?

Answer: Rasmus Lerdorf is known as the father of PHP.

54.Is variable name case sensitive in PHP?

Answer: Yes,variable name is case sensitive in PHP that's why $language and $LANGUAGE are treated as two different variables.

55. Is any PHP keyword case sensitive?

Answer: No, PHP keyword is not case sensitive. For example Echo "www.eitworld.com"; , echo "www.eitworld.com"; , EcHo "www.eitworld.com"; , eChO"www.eitworld.com"; all these echo statements will work equally and give the same result.

56. How to delete a file in PHP?

Answer: Unlink() function is used to delete a file in PHP.

57.What is the use of fopen function of PHP?

Answer: fopen function is basically used to open a file in a particular mode (read, write, append).

58.What is the use of 'r' mode in fopen() function?

Answer: r mode here represents reading.This mode opens a file for read only use. If the file does not exists then it returns NULL.

59.What is the use of 'w' mode in fopen() function?

Answer: w mode here represents writing.This mode opens a file for write only use. In addition, you can erase the data present in the file and begin writing data at the beginning of the file.If the file does not exists then it creates new file.

60.What is the use of 'a' mode in fopen() function?

Answer: a mode here represents append.This mode also opens a file for write only use but data present in the file preserved and you will begin writing data at the end of the file.If the file does not exists then it creates new file.

61.What is the use of 'r+' mode in fopen() function?

Answer: r+ mode here represents Reading + Writing.This mode opens a file so that it can be read from and written to. In this mode you can begin writing data at the beginning of the file.If the file does not exists then it creates new file.

62.What is the use of 'w+' mode in fopen() function?

Answer: w+ mode here represents Reading + Writing.This is exactly the same as r+, except that it deletes all information in the file when the file is opened.If the file does not exists then it creates new file.

63.What is the use of 'a+' mode in fopen() function?

Answer: a+ mode here represents Reading + Writing.This is exactly the same as r+, except that it appends new data at the end of file.If the file does not exists then it creates new file.

64.Which function is used to close the file in PHP?

Answer: PHP flocse function is used to close a file in PHP.

65.What is the differences between $a != $b and $a !== $b?

Answer: != means inequality (TRUE if $a is not equal to $b) and !== means non-identity (TRUE if $a is not identical to $b).

66.What do you mean by decision making statements in PHP?

Answer: Decision Making statements are used to divert the flow of the control according to some scenarios. You may want to perform some work only when some particular condition is fulfilled.

67.How many decision making statements are their in PHP?

Answer: There are following types of Decision Making statements to manipulate a condition-

1.If statement

2.If...Else Statement

3.If...ElseIf...Else Statement

4.Switch...case Statement

68.How to find the position of the first occurrence of a substring in a string?

Answer: strpos() function is used to find the position of the first occurrence of a substring in a string.

69.What is the use of "ksort" in php?

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

70.Differences between GET and POST methods ?

Answer:We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method.

71.What does the unlink() function means?

Answer: unlink function is used to delete file from a file system.

72.What is meant by nl2br()?

Answer: nl2br() is a function that convert new line (\n) to break tag (<BR>).

73.Which function can be used to remove duplicate values from an array?

Answer: array_unique() funciton can be used to remove duplicate values from an array.

74. Which sql query will be used to retrive 1-50 records from a STUDENT table ?

Answer: Following SQL query would be used for this purpose:

$sql = "SELECT * FROM STUDENT LIMIT 50";
75.What is the use of LIMIT clause?

Answer: LIMIT clause is used to specify the number of records to return.LIMIT clause is very useful for retriving data from large tables it can provide multipage results easily.

76.Which sql query will be used to retrive 20-25 records from a STUDENT table ?

Answer: Following SQL query would be used for this purpose:

$sql = "SELECT * FROM STUDENT LIMIT 6 OFFSET 19";
77.How can we get second of the current time using date function?

Answer: We have to use following statement to get second of the current time using date function:

<?php $second = date("s"); ?>
78.Which sql query will be used to delete all the rows from a STUDENT table ?

Answer: Following SQL query would be used for this purpose:

$sql = "DELETE FROM STUDENT";
79.How do you define a constant in PHP?

Answer: Constants in PHP are defined using define() function, like define("newconstant", 22);

80.What do you mean by $_REQUEST variable ?

Answer: The $_REQUEST variable contains the content of $_GET , $_POST and $_COOKIE. PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

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

Answer: strlen() function is used for finding length of string and count() function is used for finding length of array.

82.Does PHP support multiple inheritances?

Answer: No, PHP support only single level of inheritance. A class can be inherited from a single class using keyword 'extended'.

83.What is the difference between the unlink and unset functions?

Answers: unlink() function deletes the given file from the file system whereas unset() function makes a variable undefined.

84. What do you mean by Arithmetic operators and give one example?

Answer: Arithmetic operators are used to perform arithmetic operations like addition, subtraction etc. For example if $a=2 and $b=3 then $a+$b will be 5.

85.How can you create a table in MySql database?

Answer:To create a table in MySQL, we can use CREATE TABLE statement as shown below:

CREATE TABLE tablename(columnName1 datatype,columnName2 datatype,...)
86.How can we submit a form without a submit button?

Answer: You can submit a form without using Submit button for this you can use normal hyper links to submit a form. But you need to use some JavaScript code in the URL of the link. For example:

<a href="javascript: document.myform.submit();">Submit Me
87.How can we get the value of current session id?

Answer: The session_id( ) function is used to get the current session id. It returns the session id for the current session.

88.What is use of in_array() function in php ?

Answer: in_array used to checks if a value exists in an array

89.How can we increase the execution time of PHP ?

Answer: By default the maximum execution time of a PHP script is 30sec. If you want to change the following setup go inside php.ini file set max_execution_time = 60;

90.Is "$7var" valid variable name?

Answer: No, "$7var" is not a valid variable name because the name can not start with the digit.

91. Is "$my_var" valid variable name?

Answer: Yes, "$my_var" is a valid variable name.

92.What do you mean by local scope of a variable?

Answer: Local scope of a variable specifies that the accessibility of the variable is limited to a particular block or function.

93.What do you mean by global scope of a variable??

Answer: Global scope of a variable specifies that the variable can be accessed from anywhere in the document and from any function.

94.What do you mean by PHP Functions?

Answer: A function is a block of code that performs one or more particular tasks.There are two types of functions in PHP as given below:

1. Built in functions- These functions are already defined in php by php developers. Php is very rich in this matter.

2. User defined functions- Besides built in functions, a user can create a function according to the requirement.

95.What is the need to create a function?

Answer: While writing a program, there may be some part of code which we want to be executed many times at different places. Therefore, writing the code at all the places will make the program longer, annoying and more complicated.There comes the use of a function. We can create a function of the code that we want to be executed many times. Thus we have to write the code only once and now we just have to call the function wherever we want that code.

96.How can we define a variable accessible in functions of a PHP script?

Answer: We can define a variable accessible in functions of a PHP script using the global keyword.

97.How to select a database?

Answer: We can select a database by using following statement:

mysql_select_db($db_name);
98.How to delete a file from the system?

Answer: Unlink() function is used to delete the given file from the file system.

99. What are default session time and path?

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

100.What are the different types of errors in PHP?

Answer: Three are three types of errors in php :

1. Notices: variable is undefined.

2.Warning: it is not critical error. it gives permission execute the script but shows warning message that means there is still a error.

3. Fatal : it is critical error because it stops the execution of the script.