PHP Interview Questions (Beginner Level) – Short Answers

 

🔹 PHP Interview Questions (Beginner Level) – Short Answers

  1. What is PHP?
    → PHP is a server-side scripting language used to create dynamic websites.

  2. When and why is it used?
    → Used for web development to handle forms, sessions, databases, and more.

  3. What are the main features of PHP?
    → Open-source, server-side, platform-independent, supports databases.

  4. Difference between echo and print?
    echo is faster and can print multiple values; print returns 1 (used in expressions).

  5. How do you declare variables in PHP?
    → With $ symbol. Example: $name = "John";

  6. What are data types in PHP?
    → String, Integer, Float, Boolean, Array, Object, NULL.

  7. Difference between == and ===?
    == compares values, === compares value + data type.

  8. What are superglobals?
    → Built-in global variables like $_GET, $_POST, $_SESSION, etc.

  9. How does PHP handle forms (GET vs POST)?
    $_GET shows data in URL; $_POST hides data. POST is safer for sensitive data.

  10. Difference between include and require?
    → Both include files. require stops script on error, include gives warning.

  11. What is the use of isset() and empty()?
    isset() checks if variable is set. empty() checks if it's empty.

  12. Difference between single (') and double (") quotes?
    'text' prints as-is. "text $var" allows variable parsing.

  13. How to define a constant?
    define("SITE_NAME", "MyWebsite");

  14. Different types of arrays?
    → Indexed, Associative, and Multidimensional.

  15. Indexed vs Associative arrays?
    → Indexed uses numbers ($arr[0]), associative uses keys ($arr["name"]).

  16. How to loop through an array?
    → Use foreach($arr as $item) or for loop.

  17. Types of loops in PHP?
    for, while, do...while, foreach.

  18. How to define a function in PHP?
    function sayHello() { echo "Hello"; }

  19. How to handle errors in PHP?
    → Use error_reporting(), try-catch, die(), or set_error_handler().

  20. How to start a session in PHP?
    session_start();

  21. Difference between cookies and sessions?
    → Cookies are stored in browser; sessions are stored on server (more secure).


Comments

Popular posts from this blog

PHP INTERVIEW QUESTIONS

PHP Intermediate Questions Interview Preparation