PHP Interview Question Answers List:

Q: What is PHP?

PHP stands for Hypertext preprocessor and it is a well-known language to develop a web application. In a short definition, PHP is a server-side, open-source technology which is used to develop web applications ( Web applications help us to process data on the server-side and to generate dynamic web pages for clients ).

Q: Which data types are available in PHP?

PHP support various data types such as strings, numeric types complex data types like array and objects. There is a total of eight data types available in PHP that are integer, float, string, boolean, array, object, resource and NULL.

Q: In how many ways we can embed PHP code in an HTML ways?

There are special three markup tags can be use to include PHP code in HTML.

// Most common tag
<?php Write PHP Code Here ?>

<? Write PHP Code Here ?>

<script language="php"> Write PHP Code Here </script>


Q: What are the rules for naming a variable in PHP?

  • Variable name must start with a letter or underscore character.
  • We can use numbers, letters and underscores in variable name but we can not use social characters such as +, %, -, (, ), & etc.

Q: What is Null in PHP?

NULL is a special type in PHP and it only has single value NULL.

$var1 = NULL;

It is case insensitive you can also write like this

$var1 = null;

In Boolean context, NULL evaluates to FALSE. 

Q: How can we generate random numbers in PHP?

The rand() function is used to generate a random number in PHP. This function can generate numbers within a given range. Furthermore to prevent the regular pattern of numbers we can use srand() function. The srand() function specifies the seed number as its argument.



Q: How can we redirect a page using PHP?

The PHP header() function which supplies a raw HTTP header to the browser. This header() function can be used to redirect to another location. To prevent any other parts of the page from loading the redirection script should be at the top of the page. To specify the target we have to use Location: After using this function the exit() function can be used to halt parsing of rest of the code.

Q: How to add comments in PHP?

Comments are not used to perform any function in the program but they really useful for developers. Developers can write comments with variables and functions to remember their working (purpose) in the program. There are two ways to add comments:

  • Single Line comments
  • Multi-Line comments

Single-Line Comments:

// Single comment using // symbol  
# Single comment using # symbol   
echo "Welcome to Owlbuddy";  

Multi-Line Comments:

These multiline
comments also 
use to hide 
echo "Welcome to Owlbuddy";  


Q: What is session in PHP?

PHP sessions are a way to access data among different web pages of the website. All the session variables and their values stored in a file in the temporary directory on the server. With the help of PHP sessions, we can share various kind of data among all the pages of the website such as login_status, username etc.

// Starting the session
// Setting session variables and values
$_SESSION["login_status"] = "true";
$_SESSION["username"] = "Abc";


Q: What is array in PHP?

In simple words, an Array is variable which makes us able to store more than one same kind values using a single variable name.

There is a total of three types of the array in PHP. 

  • Indexed array
  • Associative array
  • Multidimensional array