Php Interview Questions With Answers 2022

By | December 31, 2021
Php Interview Questions With Answers

Welcome to JobsCaptain. We hope you are all doing well. This article is designed to suit the needs of students / professionals who intend to prepare for interview calls on PHP.

Such a frantic search consumes a lot of time & energy, as it requires goes through huge volume of PHP Technology. So in order to solve this dilemma we come up with PHP INTERVIEW QUESTIONS WITH ANSWERS, which will equipped to deal with such problems.

Often for the purpose of preparing you to struggle to look for important topics & browse through some voluble concepts, which you feel might be asked in an interview.

Content Index hide

Basic PHP Interview Questions for Freshers

There is given general Php interview questions with answers that have been asked in many companies. Let’s see the list of top core PHP interview questions.

What is PHP?

View Answer

PHP is a web language based on scripts that allows developers to dynamically create generated web pages.

Namely Php is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can create sites using its CMS.

WordPress, osCommerce are the famous CMS of php. Truly it is also an object oriented programming language like java, C-sharp etc. It is very easy for learning.


What does the initials of PHP stand for?

View Answer

PHP means PHP: Hypertext Preprocessor.


Which programming language does PHP resemble to?

View Answer

PHP syntax resembles Perl and C.


What does PEAR stands for?

View Answer

PEAR means “PHP Extension and Application Repository”. It extends PHP and provides a higher level of programming for web developers.

Likewise PEAR is a code repository containing all kinds of php code snippets and libraries. PEAR also offers a command-line interface that can be used to automatically install “packages”.
$message vs. $$message in PHP


Differences between GET, POST and REQUEST methods ?

View Answer

GET and POST are used to send information from client browser to web server. In case of GET the information is send via GET method in name/value pair and is URL encoded.

The default GET has a limit of 512 PHP INTERVIEW QUESTIONS 2 characters. The POST method transfers the information via HTTP Headers. 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.


What are the different errors in PHP?

View Answer

There are 4 basically types of error.

Parse Error – Commonly caused due to syntax mistakes in codes e.g. missing semicolon, mismatch brackets.

Fatal Error – These are basically run time errors 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.

Warning Error – These occurs when u 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.


What is session and why do we use it?

View Answer

Session is a super global variable that preserve data across subsequent pages. Especially Session uniquely defines each user with a session ID, so it helps making customized web application where user tracking is needed.


What is cookie and why do we use it?

View Answer

Cookie is a small piece of information stored in client browser. It is a technique used to identify a user using the information stored in their browser (if already visited that website) . Specifically using PHP we can both set and get COOKIE.


How to set a page as a home page in a php based site?

View Answer

index.php is the default name of the home page in php based sites.


What is the difference between $message and $$message?

View Answer

The main difference between $message and $$message is that former one is a simple variable and later is a reference variable. $message is a variable with a fixed name and it consists of a fixed value. $$messages contains the variable itself.


Differences between GET and POST methods ?

View 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.


What is htaccess? Why do we use this and Where?

View Answer

.htaccess files are configuration files of Apache Server which provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.


How can we destroy the cookie?

View Answer

Set the cookie in past.


List out some tools through which we can draw E-R diagrams for mysql.

View Answer

Case Studio and Smart Draw.


How can PHP and HTML interact?

View Answer

It is possible to generate HTML through PHP scripts, and it is possible to pass information from HTML to PHP.


How can PHP and Javascript interact?

View Answer

PHP and Javascript cannot directly interacts since PHP is a server side language and Javascript is a client side language. However we can exchange variables since PHP is able to generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.


Core Php Interview Questions and Answers

Read advance PHP interview questions and answers for experienced developers (while also covering some beginner concepts). These PHP questions are very important if you have 5 years of experience.

What is meant by urlencode and urldecode?

View Answer

URLencode returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. urldecode decodes any %## encoding in the given string.


What is the difference between the functions unlink and unset?

View Answer

unlink() deletes the given file from the file system. unset() makes a variable undefined.


How can I execute a PHP script using command line?

View Answer

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument.


How the result set of Mysql be handled in PHP?

View Answer

The result set can be handled using mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object or mysql_fetch_row.


Is it possible to remove the HTML tags from data?

View Answer

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


What is ORM?

View Answer

ORM is Object Relation Mapper. ORM is programming technique for converting data between incompatible type systems in object-oriented programming languages.


What is dispatcher in Zend?

View Answer

Dispatching is the process of taking the request object, Zend_Controller_Request_Abstract, extracting the module, controller, action name, and optional parameters contained in it, and then instantiating a controller and calling an action of that controller.


What is Bootstrap in Zend?

View Answer

In Zend Framework, bootstrapping is the process that loads your application. This includes, but is not limited to the Session.

Furthermore any resources needed by your application to process the request (the dispatch) to the application is bootstrapped/loaded/initialized before the request is fulfilled, e.g. before the controller delegates any input to the model and creates a response that is send back to the client.


What is New Relic. What is benefits of this software?

View Answer

New Relic is software as a service (SaaS) that monitors your Website and mobile applications(Android, iOS) in real-time that run in different environments like cloud, on-premise and hybrid.

Following are few benefits of New Relic:

  1. Monitoring your website regularly.
  2. Downtime Notification by email.
  3. Custom Error recording and then report you in email & also can view in newrelic website.
  4. Key Transaction tracking:
    You will be able to see where your application is spending most of its time (e.g. in the controller, model OR database).
  5. External Service Call Recording (Webservices)

What is Apdex?

View Answer

Apdex means Application Performance Index. It is standard method for reporting & comparing the performance of software.

Purpose: Analyse the performance, user satisfaction & expectation then Convert into percentage.


What is the use of rand() in php?

View Answer

It is used to generate random numbers.If called without the arguments it returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 6 and 12 (inclusive), for example, use rand(6, 12).

This function does not generate cryptographically safe values, and should not be used for cryptographic uses. If you want a cryptographically secure value, consider using openssl_random_pseudo_bytes() instead.


What is mean by an associative array?

View Answer

Associative arrays are arrays that use string keys is called associative arrays.


What is SQL injection?

View Answer

SQL injection is a malicious code injection technique.It exploiting SQL vulnerabilities in Web applications.


Quote from CGI FAQ.

View Answer

Firstly, the the HTTP protocol specifies differing usages for the two methods. GET requests should always be idempotent on the server.

This means that whereas one GET request might (rarely) change some state on the Server, two or more identical requests will have no further effect.


What is the functionality of the function htmlentities?

View Answer

Convert all applicable characters to HTML entities. This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.


How can we convert the time zones using PHP?

View Answer

By using date_default_timezone_get and date_default_timezone_set function on PHP 5.1.0

date_default_timezone_set(’Asia/Tokyo’);
$stamp = mktime(8, 0, 0, 1, 1, 2000);
date_default_timezone_set(’US/Eastern’);
echo ‘
‘, date(DATE_RFC1123, $stamp) ,’
‘; ?>


What does accessing a class via :: means?

View Answer

:: is used to access static methods that do not require object initialization.


Is it possible to protect special characters in a query string?

View Answer

Yes, we use the urlencode() function to be able to protect special characters.


Whether PHP supports Microsoft SQL server ?

View Answer

The SQL Server Driver for PHP v1.0 is designed to enable reliable, scalable integration with SQL Server for PHP applications deployed on the Windows platform.

Likewise the Driver for PHP is a PHP 5 extension that allows the reading and writing of SQL Server data from within PHP scripts. using MSSQL or ODBC modules we can access Microsoft SQL server.


What is CURL?

View Answer

CURL means Client URL Library. CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols.


How to create unique random password?

View Answer

echo md5(uniqid(rand(), true));


Php Functions Question Answer

Given below is the list of most popular PHP Functions interview questions and answers, which are commonly asked in the interviews.

How we know the total number of elements of Array?

View Answer

There are two methods through which we can know the total number of elements:

sizeof($array_var)
count($array_var)


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

View Answer

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


How to strip whitespace (or other characters) from the beginning and end of a string?

View Answer

The trim() function removes whitespaces or other predefined characters from both sides of a string.


How to find the length of a string?

View Answer

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


What is the use of isset() in php?

View Answer

This function is used to determine if a variable is set and is not NULL.


What is the use of “ksort” in php?

View Answer

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


How to delete a file from the system in Php?

View Answer

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


What is the use of “echo” in php?

View Answer

It is used to print a data in the webpage, Example: <?php echo ‘Car insurance’; ?> , The following code print the text in the webpage.


How to include a file to a php page?

View Answer

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


require_once(), require(), include().What is difference between them?

View Answer

require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example.

This way you make sure you don’t include the file more times and you will not get the “function re-declared” error.


What is the use of ‘print’ in php?

View Answer

This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.

Example
print(‘PHP Interview questions’);
print ‘Job Interview ‘);


What is use of in_array() function in php ?

View Answer

in_array used to checks if a value exists in an arraY


What is use of count() function in php ?

View Answer

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


What is use of header() function in php ?

View Answer

The header() function sends a raw HTTP header to a client. We can use herder() function for redirection of pages. It is important to notice that header() must be called before any actual output is seen.


What are the different functions in sorting an array?

View Answer

Sort(), arsort(), asort(), ksort(), natsort(), natcasesort(), sort(), usort(), array_multisort(), and uksort().


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

View Answer

imagetypes() gives the image format and types supported by the current version of GD-PHP.


What is the difference between mysql_fetch_object() and mysql_fetch_array()?

View Answer

The mysql_fetch_object() function collects the first single matching record where mysql_fetch_array() collects all matching records from the table in an array.


What are encryption functions in PHP?

View Answer

CRYPT(), MD5()


Code Questions Answers

Do you want to learn or test your PHP skills for an interview? Here we provided Php code questions that commonly asked in giant IT Company. Core PHP interview questions with detailed answers and code samples.

How to destroy one session?

View Answer

unset($_SESSION[‘object’]);


How to delete a php file from server?

View Answer

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


How to convert array to json in php?

View Answer

$array = array(‘one’,’two’);
echo json_encode($array); //use json_decode for decode


How to call constructor of parent class?

View Answer

parent::constructor()


How to create a session, set a value in session and how to Remove data from a session?

View Answer

Create session : session_start();
Set value into session : $_SESSION[‘USER_ID’]=1;
Remove data from a session : unset($_SESSION[‘USER_ID’];


How do you connect mysql database with PHP ?

View Answer

We can connect Mysql Database with PHP using both Procedural and Object oriented style like below.

$link = mysqli_connect(“localhost”, “username”, “password”, “dbofpcds”);
$mysqli = new mysqli(“localhost”, “username”, “password”, “dbname”);
and in old type of connectivity were
$link = mysql_connect(“localhost”, “username”, “password”);
mysql_select_db(“database”,$link);


How can we extract string “pcds.co.in ” from a string

“http://[email protected] using regular expression of PHP?

View Answer

preg_match(“/^http:\/\/.+@(.+)$/”,”http://[email protected]”, $matches);
echo $matches[1];


Suppose your Zend engine supports the mode <? ?> Then how can you configure your PHP Zend engine to support <?PHP ?> mode ?

View Answer

In php.ini file:
set
short_open_tag=on
to make PHP support


How we get IP address of client, previous reference page etc?

View Answer

By using $_SERVER[‘REMOTE_ADDR’],
$_SERVER[‘HTTP_REFERER’] etc.


How can we encrypt and decrypt a data present in a MySQL table using MySQL?

View Answer

AES_ENCRYPT () and AES_DECRYPT ()


How can we get the browser properties using PHP?

View Answer

By using
$_SERVER[’HTTP_USER_AGENT’] variable


How can we destroy the cookie?

View Answer

Set the cookie in past


Frequently Asked Questions

Here we Listed of Most Frequently Asked PHP Interview Questions with detailed Answers and Code Examples for Freshers and Experienced Candidates.

Who is the father of PHP ?

Rasmus Lerdorf is known as the father of PHP.

What is the main difference between PHP 4 and PHP 5?

PHP 5 presents many additional OOP (Object Oriented Programming) features.

What you can do with PHP?

Some interesting things, you can do in PHP. Also, there are a lot of hidden features like you can create .png image for games, create a .pdf files, GTK applications and much more.

How to stop the execution of the php script?

exit() function which stops the current php script (Execution of the page).

How to redirect a page in php?

The following code can be used for it,
header(“Location:index.php”);

Is variable name casesensitive in Php?

Yes variable name casesensitive in Php.

What is meant by nl2br()?

Inserts HTML line breaks (<br/>) before all newlines in a string.

What is the difference between PHP and JavaScript?

The difference lies with the execution of the languages. PHP is server side scripting language, which means that it can’t interact directly with the user. Whereas, JavaScript is client side scripting language, that is used to interact directly with the user.

How can we create a database using PHP and MySQL?

We can create MySQL database with the use of mysql_create_db(“Database Name”)

How can we increase the execution time of a PHP script?

by changing the following setup at php.inimax_execution_time = 30; Maximum execution time of each script, in seconds.

Visit regular our JobsCaptain.

Thanks For choosing this Php interview questions with answers article. If you liked please share with your friends. 

5 thoughts on “Php Interview Questions With Answers 2022

  1. issac

    Amazing! It’s truly a remarkable article, I have got much clear idea concerning
    from this article.

    Reply
  2. Kevin Parekh

    Thank u sharing PHP Interview Questions for 10 years of experience.

    Reply
  3. Kyara Loki

    It’s really a great and helpful piece of info. I’m glad that you just shared this helpful
    info with us. Please stay us informed like
    this. Thanks for sharing.

    Reply
  4. Tejas Modi

    I have 10 years of experience and these PHP Interview Questions and Answers help me a lot for getting Job! Awesome Team JobsCaptain.

    Reply
  5. Butani

    Every Php developer should read this php interview question.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *