Php Developer Interview Questions Answers

Php is one of the most demanding web development language, there are many popular frameworks are written in php, like wordpress, drupal etc. demand of good php programmer increasing day by day.

Here we learn some commonly asked PHP developer interview questions answers for beginners and experienced developer.

What is PHP?
PHP stands for Hypertext Preprocessor, an open source server-side scripting language widely used for web development. PHP was introduced by Rasmus Lerdorf.
php interview questions
  1. What are the popular CMS (Content Management Systems) built in PHP?
    There are many CMS framework written in PHP, like WordPress, Drupal, Magento, Joomla etc.
  2. What is PEAR in PHP?
    PEAR stands for PHP Extension and Application Repository.

    PEAR is the framework and repository for reusable PHP components, which provides a command line interface to install "php packages" automatically.

  3. What is "echo" in PHP?
    PHP echo is used for displaying the output value for one or more string
  4. What is the difference between "echo" and "print" in PHP?

    Php "echo" can output one or more string, but php "print" can only output one string and returns 1.

    We should always use Echo instead of Print, Echo is faster than print because it does not return any value.

  5. What is full form of PHP? and what scripting engine is used?
    PHP was known as Personal Home Page when Rasmus Lerdorf initiated.

    PHP is powered by Zend Engine 2.

  6. What are the popular frameworks in PHP?
    Here are some popular php frameworks
    • PHP Cake
    • CodeIgniter
    • Yii 2
    • Symfony
    • Zend Framework
  7. What are magic constants in PHP?
    PHP magic constants are predefined constants, They start with a double underscore (__) and end with a double underscore (__). They are case-insensitive.

    Examples: __LINE__ , __FILE__ , __DIR__ , __METHOD__

  8. How many types of array are there in PHP?
    In PHP, there are three types of Array.
    • Indexed Array
    • Associative Array
    • Multidimensional Array
  9. What is the difference between indexed and associative array?

    The indexed array elements stored in an indexed form, index starts from 0, look at the example below.


    In associative array, elements stored with name, like example below

  10. What is the differentiate between require and include?
    Include and Require both are used to include a file within a file, but if data is not found "include" shows warning whereas "require" shows fatal error.
    <?php require("subMenu.php"); ?>
    <?php include("subMenu.php"); ?>
  11. Is PHP a strongly typed programming language?
    No. PHP is a weakly typed or loosely typed programming language.

    Which means PHP does not need to declare data type of the variable when we declare any variable like many other programming languages C#, Python etc.

    We can store any type of values in a variable, after assigning values the variable become of that type.

  12. What is "variable variables" in PHP?
    Double dollar $$ is used to declare variable variables in PHP. Indicates the value of a variable is used as the name of the other variable.
    $str = "Hello";
    $$str = " How Are You"; //declaring variable variables
    echo "$str ${$str}"; //It will print "Hello How Are You"
    echo "$Hello"; //It will print "How Are You"
  13. What does explode() and implode() functions do?
    explode explode() function is used for spliting a string into an array, and implode implode() function is used for naking a string by combining the array elements.
    $text = "Hello How are you doing?";
    print_r (explode(" ",$text));
  14. How to check the data type of any variable in PHP?
    There is gettype gettype() function to check the data type of any variable.
    echo gettype(true).''; //boolean
    echo gettype('How are you').''; //string
    echo gettype(100).''; //integer
    echo gettype(null).''; //NULL
  15. What is garbage collection in PHP?
    Garbage collection is an automated feature of managing unused session in PHP, it helps cleaning up all sessions data which are no longer in use.

    Garbage collection runs on default session directory “tmp”

    • maxlifetime session.gc_maxlifetime (default value, 1440)
    • divisor session.gc_divisor (default value, 100)
    • probability session.gc_probability (default value, 1)
  16. When to use escape string mysqli_real_escape_string() function?
    Here is an example

    escape string mysqli_real_escape_string() function can be used when we want to escape special characters from the string that will be used in a SQL statement

    $mysqli = new mysqli("localhost","myuser1","myPassword1","mydbname");
    // Escape special characters, if any
    $firstname = $mysqli -> real_escape_string($_POST['firstname']);
    $lastname = $mysqli -> real_escape_string($_POST['lastname']);
  17. How a cross-site scripting attack can be prevented by PHP?
    In Php we have Html entities Htmlentities() function to prevent cross-site scripting attack.
    $mystr = 'Go to WebTrainingRoom.Com';
    echo htmlentities(mystr);
  18. How single and multi line comment is done in PHP?
    PHP single line comment is made in two ways:
    • Uing hash # (Unix Shell style single line comment)
    • Also can use double back slash //
    // This is a single-line comment
    # This is also a single-line comment

    The multiple line PHP comment begins with " /* " and ends with " */ ". below is an example.

    example of a multiple-lines comment block
    that spans over multiple
  19. What are the different type of loops available in Php programming?
    Like any other programming language, we can define all type of loops in php, like for loop, foreach loop, Do loop, do while loop etc.

    Learn more about php loop with examples

  20. How to define session in php?
    We can start using session by calling session_start() function. Here is an example how we can define session variable in php code.
       if(!isset($_SESSION['userinfo'] ))
          $_SESSION['userinfo'] = "WebTrainingRoom";
       $msg = "Hello ".  $_SESSION['userinfo'];
       $msg .= ", Welcome.";
    echo ( $msg );  

    Learn more about PHP Session Management with example

  21. What are the superglobals in php?

    Superglobals are built-in variables that are always available in all scopes. and we can access those variables from any function, class or file without having to do anything special.

    • ENV $_ENV
    • GET $_GET
    • POST $_POST

    Learn more about Php superglobal Variables with examples.

  22. How to read configuration in php application?
    We can read configuration value from php.ini file using ini_get method like ini_get("mysql.default.user"), here is an example how we can read database connection related information from ini file.
    $db = mysqli_connect(ini_get("mysql.default.user"),

    learn more about how to read Configuration setting from php.ini

  23. How to set up mysql database connection string in php application?
    we can ceate database connection object by creating a new instance of mysqli object like example below.
        $mysqli = new mysqli("localhost", "username", "password", "dbname");

    read more about php mysql connection.

  24. How we can create class object in php?
    Php support object oriented programming, we can define a class and then create object of that class like code below.
    class car {            
    public  $model="Not Set";
    public  $color="Not Set";
    public  $price=0.0;

    Learn more about how to cerate class and Objects in php code

  25. What is the use of enctype="multipart/form-data" in php form?
    We can set enctype to multipart, when we want to create form to allow user to upload file in our system like code below.
    <form action="" method="POST" enctype="multipart/form-data">
    	<input type="file" name="fileUpload1" id="fileUpload1"/>
    	<input type="submit" value="Upload" />		
  26. How we can make ajax post in php code?
    The most popular way to make an ajax call from php code is, by using jquery ajax submit.
          success: function(data) {
            alert('AJAX call successful!');
            alert('response from the server' + data);
          error: function() {
            alert('There was some error response from  AJAX call!');

    Read more details about php ajax form submit.

PHP Course Online and Latest Interview Questions Answers
php course online
learn php
Interview Question Answers | Fresher Job Interview Tips