Top 40+ PHP Interview Questions And Answers For Freshers

Published on 8th Mar 2018 in PHP

This is set of questions which is generally asked PHP interview question and answer for freshers.Important PHP Interview Questions with answers.These questions are frequently asked in interview by IT Companies.Get the top PHP interview questions here. You can read important PHP Interview Questions and answer.

 Top 40+ PHP Interview Questions And Answers For Freshers

Q. Who is father of PHP ?

Rasmus Lerdorf

Q. What is PHP ?

Hypertext Preprocessor is server side scripting language that allows the features of creating web pages dynamically .PHP allows the webpage to connect with the database. PHP Scripts are executed on the server.


Q. What is echo in PHP ?

echo is used to print data in webpage. eg. <?php echo "PHP Cluster"; ?>. This code will print text PHP Cluster on webpage.


Q.  What is PEAR in PHP ?

PEAR(PHP Extension and Application Repository) is a framework and repository for reusable PHP components.It is a code repository containing all type of PHP script and library.

Q. How to declare array in PHP ?

$arr= array('php','cluster','vikash');

Q. How to include a file in PHP ?

To include a file in PHP we use include() or require() function.

Q. What is the best way to copy a file from within a piece of php code ?

Use the inbuilt copy() function

Q.  In php which method is used getting browser properties ?


Q.  LAMP stands for

Linux Apache Mysql PHP

Q.  Which function is used to pick one or more random value from array() ?


Q. Which type of variable have php ?

  Multitype variable

Q. Is PHP support Multiple inheritance ?


Q. In PHP which is used as error control operator ?


Q. Which regular expression is used in PHP ?

Posix extended and Perl Compatible Regular Expression (PCRE)

Q. Which function is used to check if a function is already defined ?

Bool function_exits(function name)

Q. How to redirect page in PHP ?

header(‘Location: http://www.example.com/’);


Q. Which function is used to terminate the script execution in php ?


Q. Which operator is used to concatenate two strings in php ?

Dot operator ( . )

Q. How to use cookie ?

setcookie(‘name of cookie’,’value of cookie’,’expire time’,’domain’,’path’);




{   print_r($_cookie[‘user’]);




echo “cookie doesn’t exist”;



Q.  Is it possible to submit a form without submit button ?


Q. Which data type are treated as array ?



Q. Is php directly coded into XHTML documents ?


Q. Casting operator introduced in PHP is -------?

Int 64


Q. Which function can be used to compare two strings using a case sensitive binary algorithm ?



Q. Which of the following function require allow_url_fopen must be enabled ?

(a) Include                  (b) require      (c) both

Ans: (C)


Q. Which of the following is not valid variable name ?

(a) $php-cluster-vikash     (b) $vik              (c) $PhpClusterVikash              (d) $php_cluster_vikash

Ans: (a)


Q. How many inbuilt function is used to retrieve data in php in result set of MYSQLi ?

In four ways we can fetch data

1)  mysqli_fetch_row.

2)  mysqli_fetch_array

3)  mysqli_fetch_object

4)  mysqli_fetch_assoc

Q. How to create database using PHP & MySQL?

mysql_create_db(“Your database Name”);

Q. What is the difference between unlink and unset php inbuilt function?

Unlink() function deletes the given file name from file system.

Unset() function makes a variable undefined means variable without value.

Q. How to register a variable in session?


$_SESSION[‘name’] = “PHPCluster”;

Q. How to check your PHP installation?

PHP provides mainly two types of interface which are :

CLI – Command Line Interface

CGI – Common Gateway Interface

If php is installed in your system in php directory You can check it via these method.

1)      Run "phpphp -v" command to check the Command Line Interface (CLI).

2)       Run "phpphp-cgi -v" command to check the Common Gateway Interface (CGI).

Q.  What is the difference between function and method?

When a function is created inside a class then, it is called method but when declared outside a class/object   is called function.

class phpcluster{

public function cluster(){       // a called method




function cluster(){               // a function not part of an object

Q. What is use of isset() function in PHP ?

The isset () function is used to check whether a variable is set or not


Q. How to Get Current date and time with PHP ?

date('d-m-y H:i:s');


Q. What is use of explode and implode functions?
Usage of explode() and implode() function

explode() : Convert string to Array
implode() : Convert Array to string

Q. How to Print an Array in PHP ?


Q. How to get current page URL in PHP ?
$uri  = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];

echo $uri;


Q. How to send mail using PHP?

Q. How to count all elements or values in an array in PHP ?



Q. How can we get the IP address of the client in PHP ?



Q.  WAMP stands for

Windows Apache Mysql PHP


Share It
Stay Connected
Like Us on Facebook