Free Web Development Online Tutorials, Learn to Code
php mysql Interview Questions and Answers for Beginners

Php Developer Interview Questions Answers

PHP developer interview questions answers for beginners and experienced developer

php Interview Questions Answers

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?
    WordPress, Drupal, Magento, Joomla etc.
  2. What is "echo" in PHP?
    PHP echo is used for displaying the output value for one or more string
  3. 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.

  4. 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__

  5. How many types of array are there in PHP?
    In PHP, there are three types of Array.
    • Indexed Array
    • Associative Array
    • Multidimensional Array
  6. 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.

        $colors=array("red","green","blue","orange"); 
    

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

    $marks=array("Aniket"=>"70","Manish"=>"65","Jatin"=>"68");    
    
  7. 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"); ?>
    
  8. 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.

  9. What is "variable variables" in PHP?
    $$ 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"
    
  10. What does explode() and implode() functions do?
    explode() function is used for spliting a string into an array, and implode() function is used for naking a string by combining the array elements.
    $text = "Hello How are you doing?";
    print_r (explode(" ",$text));
    
  11. How to check the data type of any variable in PHP?
    There is 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
    
  12. 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”

    • session.gc_maxlifetime (default value, 1440)
    • session.gc_divisor (default value, 100)
    • session.gc_probability (default value, 1)
  13. When to use mysqli_real_escape_string() function?
    Here is an example

    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']);
    
  14. How a cross-site scripting attack can be prevented by PHP?
    In Php we have Htmlentities() function to prevent cross-site scripting attack.
    $mystr = 'Go to WebTrainingRoom.Com';
    echo htmlentities(mystr);
    
 
Php-mysql Interview Questions Answers



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