PHP Interview Questions for Freshers 2023

PHP stands for PHP Hypertext Pre-processor and is an open-source programming language that is widely used for creating a dynamic website and mobile APIs.  Following are the PHP interview questions.

Q1.  How PHP is a case-sensitive language?

PHP is partially case sensitive which refers to variable names that are case sensitive but function names are not. If the function name is defined in lower case and you call them in lower case, it will still work.

Q2. What is the command line used to execute a PHP script?

PHP Command Line Interface (CLI) is used to execute a PHP script. Syntax for the file name:

Php script.php

Q3. What is meant by “escaping to PHP”?

Php Parsing engine requires a method to differentiate between the PHP code from the other elements used in the page and is known as “escaping to PHP”.

Q4. Name the characteristics of PHP Variable?

 The characteristics of the PHP variable are:

  • The variables in PHP are denoted with a $ (Dollar sign).
  • Variables are assigned with values with = sign operator.
  • Before assigning the value to the variables, they have default values.
  • The value of the variable is the value of its recent assigned value.

Q5. What is the function of  PEAR in PHP?

PEAR is a framework and allows the reusability of PHP components. PEAR’s full form is PHP Extension and Application Repository. It consists of all PHP code Libraries.

Q6. Differentiate between PH4 and PHP5?

PHP4 does not support the oops concept and uses Zend Engine 1.

PHP5 supports the oops concept and uses Zend Engine 2.

Q7.  Label some of the Popular frameworks in PHP?

Below is the framework in PHP

    • CakePHP
    • Codelgniter
    • Yii 2
    • Symfony
    • ZenFramework

Q8.  What are the characteristics of “echo” and “print” in PHP?

Echo gives output as one or more strings but print can only give output one string return value is 1. The echo is faster than print as it does not return any value.

Q9. Differentiate between $message and $$message?

$message is used to store variable data while $$message is used for storing variable of variables. $message is used when the data is fixed and the data stored in $$ message changes dynamically.

Q10. Name the types of the array in PHP?

Below are the types of arrays in PHP:

    • Indexed Array: it is an array with a numeric key.
    • Associative array: An array in which each key has a specific numeric value.
    • Multidimensional array: It comprises one or more arrays in itself.

Q11.  What is the PHP variable-length argument function?

In PHP you can pass 0, 1, or n number of arguments which refers to variable-length argument function.

Q12. Define count () function in PHP?

The PHP count () function is used for counting total elements in an array.

Q13. What is the method used in PHP to submit the form?

Two methods used in PHP are GET and POST. The GET method is visible on the URL and is the default form method and is declared as $_GET. Only a limited amount of data is sent through GET requests.  The POST method is declared as $_POST and a large amount of data can be passed.

Q14. How can files be included in PHP?

Including files in PHP refers to reusing the content of the page and the ways to include the file in PHP are:

    • Include
    • Require

Q15. Define “include” and “require”?

If the file is sent through “include” and it does not find the file it sends the file and “require” sends the fatal error.

Q16. What are the Content Management Systems (CMS) in PHP?

  • WordPress
  • Joomla
  • Magento
  • Drupal

Q17. Define isset() function in PHP?

The isset () function is used to check whether the variable is properly defined and is not null.

Q18. What is the way to retrieve the value of a cookie?

Using the below syntax value of cookie can be retreived:

Echo $_COOKIE[“user”];

Q19. Define $_SESSION in PHP?

A session creates a file that is stored in a temporary directory on the server in which the session variable and id are stored.

Q20. Give a proper syntax to open file in PHP?

To open file in PHP fopen() function is used

Syntax: resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )

Q21. What are the functions that can be used to read files in PHP?

Below are the read functions in PHP:

    • fread()->read data of the file.
    • fgets()->read single line.
    • fgetc()->read single character.

Q22.What is the syntax for creating database connections and for queries in PHP?

  • Mysqli_query()
  • PDO::_query()

Q23. What is the syntax to stop the execution of the PHP script?

In PHP execution of the script can be stopped using exit() function.

Q24. Define Split() function in PHP

The split function is used to divide the string into an array by regular expression

Q25. How can you retrieve the IP address of a client in PHP?

$_SERVER[“REMOTE_ADDR”]; can be used to retrieve the IP address.

Q26. Why is parser important in PHP?

The parser parses the opening and closing tags of the PHP.

<?php syntax for opening tag in PHP

?>   syntax for closing tag in PHP

Q27. Define the header () function in PHP?

The header () function is used to send HTTP header to the client and it needs to be called before the actual output is sent.

Q28. What is the setcookie () function in PHP?

The function is used to set cookies along with HTTP responses.

bool setcookie (string $name,string $value, int $expire = 0, string $path, string $domain, bool $secure = false, bool $httponly = false )  

setcookie(name, value, expire, path, domain, secure, httponly);  

Q29.  How session is different from the cookie?

The major difference between session and cookie is that cookie cannot hold multiple variables but the session can. Cookies are stored on the client-side whereas session is stored on the server-side.

Q30. How are include () and require () different?

The include () function is used where you need to put data of one PHP file to another. This function continues to execute the script even if an error occurs.

The Require () function stops the execution of the script as soon as error occurs.