101 Outstanding PHP Interview Questions With Answers (A-Z)

PHP Interview Questions for Freshers

In this article, we have provided the significant PHP interview questions and answers for freshers who will be going for a job interview as a PHP developer. These PHP interview questions have been designed uniquely 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. We hope you get these PHP interview questions and answers helpful and it will also help you to expand your essential PHP skills.

Why should you read this article?

We would advise you read this blog because it provides an insight of the following:

  • A significant PHP Interview Questions and Answers which will be very helpful for those who are trying for a job in web development and want to start a career in PHP.
  • Customized PHP Interview Questions for Freshers as well as it will be useful for experienced candidates too.
  • Generally required technical PHP Interview Questions and answers in 2018.

PHP Interview Questions and Answers For Freshers

Let’s have a look at important PHP Interview Questions and Answers for freshers.

1. What is PHP?

PHP is a widely-used, open-source server-side scripting language. PHP is an acronym for “PHP: Hypertext Preprocessor.” It allows the developers to develop dynamic web applications. PHP has various frameworks and CMS for developing dynamic and interactive websites.

2. What types of loops exist in PHP?

for, while, do while and foreach.

3. How do you display the output directly to the browser?

To display the output directly to the browser, I will use the special tags <?= and ?>.

Related: Top Benefits and Importance of PHP Language

4. Describe which programming language does PHP parallel to?

The PHP syntax relates Perl and C.

5. How to create a MySQL connection?


Check out $1 VPN Offers for Students

6. How to select a database?


The PHP Data Objects (PDO) is a lightweight, and consistent interface used to access databases in PHP.

7. What is PEAR?

What is PEAR

PEAR means “PHP Extension and Application Repository.” It is a framework and distribution system for reusable PHP components. It extends PHP and gives a higher level of programming for all web developers. PEAR is divided into three different classes that are: PEAR Core Components, PEAR Packages, and PECL Packages. The PEAR Packages include functionality giving for authentication, networking, and file system features and tools for working with HTML and XML templates.

8. What is the use of “ksort” in php?

In PHP, Ksort is used to sort an array by key in reverse order.

9. What are the data types of PHP?

Integers, Doubles, Booleans, Arrays, Objects, NULL, Strings.

10. Which PHP version is actually used today?

Nowadays, PHP 7 is the actually used version.

PHP Interview Tip:

“During the interview of a potential candidate, I am aiming to understand how updated they are with the new language features as well as their level of understanding of basic operations. In my opinion, this will define how good a… Click To Tweet

| Related: Amazing Websites to Learn PHP Language Online

11. What is NULL?

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

12. What is the use of Constant Function?

A constant function is used to return the constant value.

In PHP, constant function is case sensitive. A constant function is used to return the constant value.

13. What is the correct way to start and complete a PHP block of code?

There is the two most common and correct ways to start and complete a PHP script. That is  : <?php [   —  PHP code—- ] ?> and <? [—  PHP code  —] ?>

14. What is a numeric array?

Numeric array − An array with a numeric index. The values are stored and accessed in a linear fashion.

15. Does PHP support multiple inheritances?

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

16. Describe what is the major difference between PHP 4 and PHP 5?

PHP 4 & 5
PHP 5 is an upgraded version of PHP 4. PHP 5 offers many extra OOPs features. It introduces new functions which are not found in PHP4.

In PHP 5, you have to name your constructors.

In PHP 5, Class can be declared as Abstract.

PHP 5 introduced a special function which is __autoload().

In PHP 5, Class or method can be declared as Final.

In PHP 5, Magic methods are introduced such as __call, __get, __set and __toString.

In PHP 5, ‘exceptions'(exception errors) was introduced.

In PHP 5, interfaces are introduced.

17. What are tags used?

They allow making the result of the expression between the tags directly to the browser response.

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

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

19. Is PHP supports multiple inheritance?

The PHP comprises only single inheritance which means that a class could be enlarged from just one single class utilizing the keyword ‘extended.’

20. What is the use of count function in MySQL?

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

| Related: Top Benefits and Importance of PHP Language

21. How to send a mail in PHP?

You can send an e-mail in PHP with mail() function or SMTP details.

22. Explain what the meaning of a final class and a final method is?

‘final’ is initiated in PHP 5. Final class implies that this class can’t be enlarged and a final method can’t be overridden.

23. How can you break PHP script?

I can use exit() function for that.

24. What is the default page in web server?

Most of the times it will be index page.

25. Explain how a comparison of objects done in PHP 5 is?

I can use the operator ‘==’ to test if two objects are mentioned from the corresponding class and have equal attributes and similar values. I can test if two objects are referring to the same instance of the corresponding class by the control of the identity operator ‘===’.

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

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.

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

A session is a super global variable that preserves data across subsequent pages. Session uniquely defines all users with a session ID. So it supports building a customized web application where user tracking is required.

28. Describe how PHP and HTML can interact?

Also, it is possible to make HTML into PHP scripts, and it is possible to transfer information from HTML to PHP.

| Related: Amazing Websites to Learn PHP Language Online

29. Explain which type of operation is required when passing values into an URL?

To pass values by an URL, then you require to encode and to decode them applying urlencode () and htmlspecialchars().

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

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.

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

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

32. Describe how PHP and Javascript can interact?

The PHP and Javascript could not directly interact because PHP is a server-side scripting language and Javascript is a client-side scripting language. But, we can change variables, because PHP can generate JavaScript code to be performed by the web browser and it is likely to pass particular variables behind to PHP into the URL.

33. How can we modify the value of a constant?

We cannot alter the value of a constant.

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

unset() function is used to destroy a variable whereas unlink() function is used to destroy a file.

35. Explain which is required to be able to utilize image function?

The GD library is required to be able to do image functions. It also helps to execute more image functions.

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

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.

37. What is AJAX?

whats AJAX

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.

38. What is the use of ‘imagetypes()’ function?

A function imagetypes() provides the image format and types carried by the latest version of GD-PHP.

39. What is jQuery?

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.

40. What is the difference between SQL and Mysql?

sql vs mysql

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

| Related: Top Benefits and Importance of PHP Language

41. Describe what the functions to be utilized to get the image properties (Height, Width, and Size) are?

There are three functions are used to get image properties. That functions are:

imagesy() for getting image height.

imagesx() for getting image width.

getimagesize() for getting image size.

42. What is JOIN in MySQL? What are the different types of join?

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.

43. What is the use of “echo” in PHP?

In PHP, echo is used to print data on the webpage.

Example: <?php echo ‘Car insurance’; ?>

44. Explain how failures in execution are worked with include() and require() functions?

There are some failures when using functions include() and require(). If the function require() can’t access the file then it stops with a fatal error. But, the include() function provides a warning, and the PHP script proceeds to perform.

45. How to include a file to a PHP page?

We can include a file utilizing “include() ” or “require()” function with file path as its parameter.

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

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

47. Describe how you can display information of a variable and readable through a human with PHP?

I can use print_r() function to display a human-readable result.

48. How to declare an array in PHP?

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

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

It is not actually a real function, it is a language construct. So you can utilize without parentheses with its argument list.

| Related: Amazing Websites to Learn PHP Language Online

50. Explain the PHP error what means ‘Parse error in PHP – unexpected T_variable at line x’?

This error is a PHP syntax error which is revealing that trouble at the line x stops parsing and performing the program.

51. How to Retrieve a Cookie Value?

Ex: echo $_COOKIE[“user”]

52. What is SQL injection?

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

53. What should you do to be capable to exporting data into an Excel file?

The most comprehensive way is to take data into a format supported by Excel. For example, it is likely to write a .csv file, to choose for instance comma as a separator between fields and then to open the file in Excel.

54. Describe what the default session time in PHP is?

In PHP. the default session time is until the closing of the browser

|Related:  How to Start a Career in PHP

55. How to destroy a cookie in PHP?

There is not a way to directly delete a cookie. Just use the setcookie function with the expiration date in the past, to trigger the removal mechanism in your web browser.

56. How to enlarge the execution time of a PHP script?

It is possible to enlarge the execution time of a PHP script by utilizing the set_time_limit function. It enables to enlarge the execution time of a PHP script.

57. Explain how you can pass the variable by the navigation between the pages in PHP?

I can pass the variable in the navigation by applying cookies, sessions or hidden form fields.

58. How to submit a form with a dedicated button in PHP?

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

59. Explain the difference between the functions stristr() and strstr() in PHP?

strstr() and stristr both are used to find the first occurrence of the string. stristr( ) is case insensitive, and it is an identical to superglobal() except that it is case insensitive. The strstr() – Find first occurrence of a string function.

60. Explain how you can define whether a variable is set?

I can use a boolean function. It is set defines if a variable is set and is not NULL.

| Related: Top Benefits and Importance of PHP Language

61. Explain how to parse a configuration file?

It is possible to parse a configuration file by using the parse_ini_file() function. It enables us to load in the ini file defined in the filename and returns the settings in it in an associative array. The time you run your script already processes it.

62. What is the use of goto statement?

Php also supports operator goto statement – which is the operator of unconditional transition. It can be placed to support jumping inside the PHP program. It applied to go into another area of the code.

63. Explain unset() function?

The function unset() is used for variable management. It will generate a variable undefined.

64. What function is used to escape data before storing into the database?

The function addslashes allows us to escape data before storing inside the database.

65. How do you remove escape characters from a string?

I can use stripslashes function. It allows us to remove the escape characters before apostrophes in a string.

66. Explain how you can automatically escape incoming data?

I can allow the Magic quotes entry in the configuration file of PHP. I will be helping you to escape incoming data.

67. Explain the get_magic_quotes_gpc() function?

get_magic_quotes_gpc() function shows us whether the magic quotes is switched on or not.

68. How do you remove the HTML tags from data in PHP?

I can use strip_tags() function to remove HTML tags. It allows us to remove a string from the HTML tags.

|Related:  How to Start a Career in PHP

69. Explain how you can determine a variable accessible in functions of a PHP script?

It is possible by utilizing the global keyword.

70. Describe how it is possible to return a value from a function in PHP?

It is possible to return a value by using the instruction ‘return $value;’.

But PHP doesn’t support multiple function returns.

71. Explain which cryptographic extension present generation and verification of digital signatures?

The extension PHP-OpenSSL gives some cryptographic operations including the generation and verification of digital signatures.

72. Explain how you can pass a variable by reference?

I can use an ampersand in front of it, as follows $var1 = &$var2. It will help to pass a variable.

73. Describe how it is possible to cast types in PHP?

It has to be described in parentheses before the variable which is to be cast as follows:

* (string) – cast to string

* (int), (integer) – cast to integer

* (array) – cast to an array

* (float), (double), (real) – cast to float

* (bool), (boolean) – cast to boolean

* (object) – cast to object

* (float), (double), (real) – cast to float

74. Describe when a conditional statement is ended with endif?

A conditional statement will end when the original if was followed by : and then the code block without any braces.

75. Explain how the ternary conditional operator is applied in PHP?

The ternary operator is a set of three expressions: a condition, and two operands defining what instruction need to be executed when the named condition is true or false like below:

Expression_1? Expression_2 : Expression_3;

| Related: Amazing Websites to Learn PHP Language Online

76. What is the use of func_num_args() function?

In PHP, the func_num_args() function is utilized to provide the number of parameters passed inside a function.

77. What is rand() function in PHP?

The rand() function is used to generate random numbers.

78. Explain the difference between __sleep and __wakeup method in PHP?

The __sleep method returns the array of all the variables that should be saved, while __wakeup method retrieves them.

79. Describe a session?

The definition of a session is a logical object allowing us to store temporary data over various PHP pages.

80. Explain how to initiate a session in PHP?

session_start() function allows us to activate a session.

81. Explain how is it possible to create a session id?

Generating a session id through cookies or URL parameters is possible.

82. What are MAGIC Constants in PHP?

PHP gives a large number of predefined constants to any script which it runs known as magic constants.

|Related:  How to Start a Career in PHP

83. Explain the meaning of a Persistent Cookie in PHP?

It is also called as a Permanent cookie. A persistent cookie is permanently saved in a cookie file on the computer.

84. How to know uploaded file size?

Using $_FILES[‘file’][‘size’] statement to know uploaded filesize in PHP.

The php. ini file is the default configuration file that controls variables in PHP such as upload sizes, file timeouts, and resource limits.

85. What is $GLOBALS?

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

86. What is $_SERVER?

The $_SERVER is an array adding information created by the web server. For example headers, paths, and script locations.

87. What is $_FILES?

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

88. What is $_ENV?

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().

89. What is the use of  file_get_contents() function?

The function file_get_contents() is used to read a file and store it in a string variable.

90. Explain how you can connect to a MySQL database from a PHP script?

To connect a MySQL database, i can use mysql_connect() function.

<!–?php $database = mysql_connect(“HOST”, “USER_NAME”, “PASSWORD”); mysql_select_db(“DATABASE_NAME”,$database); ?–>

91. Explain how it is possible to know the number of rows returned in the result set?

It is possible to know using mysql_num_rows() function. It returns the number of rows in the result set.

92. Explain which function provides us the number of modified entries by a query?

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

|Related:  How to Start a Career in PHP

93. Explain the difference between mysql_fetch_object() and mysql_fetch_array() in PHP?

This will provide access to the data through the field names. In PHP, the function mysql_fetch_object() will get the first single matching record where mysql_fetch_array() will get all matching records from the table in an array.

94. How can you verify the value of a provided variable is a number?

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

95. How can you examine the value of a given variable is alphanumeric?

I can use ctype_alnum function to verify whether it is an alphanumeric value or not.

96. How do you verify if a provided variable is empty?

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

97. Explain the unlink() function?

The function unlink() is applied for file system handling. It just deletes the file given as entry.

98. When did sessions end?

The sessions will automatically end when the PHP script stops executing. However, it can be manually finished by utilizing the session_write_close().

99. Explain how you can pass a variable by reference?

I can use an ampersand in front of it, as follows $var1 = &$var2. It will help to pass a variable.

100. Describe when a conditional statement is ended with endif?

A conditional statement will end when the original if was followed by : and then the code block without any braces.

|Related:  How to Start a Career in PHP

101. When does the session end in PHP?

In PHP, session will end automatically once the script finishes executing. But you can also end manually using,



Do you want to become a PHP developer? If you are looking for a job in web development, we hope these PHP interview questions and answers will get you on the right track of finding a good developer for your needs.

If you are interested in learning Advanced level PHP programming, Join any professional PHP training course. This professional course will assist you to get advanced knowledge in PHP and become a full-stack web developer.

Leave a Reply

How to Start a Career in PHP in India?
Start a Career in PHP in India