PHP interview questions

PHP Interview Questions & Answers for Freshers

Welcome for being here! In this article, we are providing you some frequently asked PHP interview questions & Answers, Which definitely clear your concept about PHP & help you to fight with interview Session easily. As you know PHP play a major role in field of web based application designing. So read the below mention PHP interview questions & answers carefully for become a good in PHP. I hope these questions will helps you & you get a Job as you want.

Some Important Point About PHP:

  • PHP is a recursive acronym for “PHP: Hypertext Preprocessor”.
  • PHP is a server-side scripting language that is embedded in HTML. It is commonly used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.
  • It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
  • PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added.
  • PHP Syntax is C-Like.
  • PHP is completely free to use.

PHP interview questions & answers

1) What is PHP?

PHP (Hypertext Preprocessor)is an open source server-side scripting language which is commonly used to design web based application. PHP is completely free and supported by a worldwide community.

2) What is Open Source Software?

Open Source Software in which the source codes are freely used, modify, and shared by anyone is called.

3) What is the use of “echo” in Php?

It is used to print a data in the web page, Example: <? Php echo ‘Car world’; ?> , The following code print the text on the web page.

4) What is the difference between the functions unlink and unset?
Unlink () deletes the given file from the file system.
Unset () makes a variable undefined.

5) Differences in between GET, POST & Request methods?

GET & POST methods are used to send the information from client browser to web server. In the case of GET method when information sending in Name/value pair then URL is encoded. GET method is used to send the small amount of data (1024 bytes). 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.

6) What are the Types of Error in PHP?

There are 4 basically types of error.

Parse Error – Parse error commonly occur due to syntax mistakes in codes e.g. missing semicolon, mismatch brackets etc.

Fatal Error – fatal error is the basically run time error 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 yet.

Warning Error – Warning error occurs when you 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.

7) What is Cookie & why do we use it?

Cookie is a small piece of information which is stored in clients browser. It is a technique that is used to identify user information stored in their browser.

8) How to declare an array in PHP?

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

9) What is use of count() function in php ?

Count () is used to count all elements in an array or something in an object.

10) What the difference is between include and require?

Both are using for handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

11) How to set cookies in PHP?

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

12) How to Retrieve a Cookie Value?

eg : echo $_COOKIE["user”];

13) to create a session?

Create session : session_start();

14) How to set a value in session?

Set value into session : $_SESSION[[‘USER_ID’];

15) How to remove data from a session?

Remove data from a session : unset($_SESSION[[‘USER_ID’]/p>

16) How to select a database in PHP?


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

Split function splits a string into array by regular expression.

Explode function splits a string into array by string.

18) How to find the length of a string?

strlen() function used to find the length of a string

19) How to Increase Execution time of Php Script?

for Change max_execution_time variable in php.ini file, you need to Open php.ini file. By Default time is 30 seconds.
The file path is xampp/php/php.ini if xampp software is using.

20) Common uses of PHP:

PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.

PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data, return data to the user.

You add, delete, modify elements within your database thru PHP.

Access cookies variables and set cookies.

Using PHP, you can restrict users to access some pages of your website.

21) Characteristics of PHP

Five important characteristics make PHP’s practical nature possible:

 Simplicity

 Efficiency

 Security

 Flexibility

 Familiarity

22) “Hello World” Script in PHP:

To get a feel for PHP, first start with simple PHP scripts. Since “Hello, World!” is an essential example, first we will create a friendly little “Hello, World!” script.



<title>Hello World</title>


<?php echo “Hello, World!”;?>



Result :


23) How to Destroy one Session?


24) How to Destroy all data resisted to a session?


25) How to Delete a Php file from the server?

$file=”full_path/filename.php” unlink($file); //make sure you have enough permission to do delete the file.

26) Multiple Inheritance supported in PHP?

Php include only single inheritence, it means that a class can be extended from only one single class using the keyword ‘extended’.

27) how can we check the value of a given variable is a number or not?

It is possible to use the dedicated function, is_numeric() to check whether it is a number or not.

28) How can we check the value of a given variable is alphanumeric?

It is possible to use the dedicated function, ctype_alnum to check whether it is an alphanumeric value or not.

29) How do I check if a given variable is empty?

If we want to check whether a variable has a value or not, it is possible to use the empty() function.

30) What does the unlink() function means?

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

31) What does the unset() function means?

The unset() function is dedicated for variable management. It will make a variable undefined.


32) How can we automatically escape incoming data?

We have to enable the Magic quotes entry in the configuration file of PHP.

33) What does the function get_magic_quotes_gpc() means?

The function get_magic_quotes_gpc() tells us whether the magic quotes is switched on or no.

34) Is it possible to remove the HTML tags from data?

The strip_tags() function enables us to clean a string from the HTML tags.



Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

CommentLuv badge