PHP Interview Questions

PHP Interview Questions

Basic PHP Questions

  1. What is PHP?

  2. What does PHP stand for?

  3. What are the main features of PHP?

  4. What is a PHP variable?

  5. How do you declare a variable in PHP?

  6. What are data types in PHP?

  7. What is the difference between echo and print?

  8. How do you write comments in PHP?

  9. What are constants in PHP?

  10. How do you define a constant?

  11. What is a PHP array?

  12. What are the types of arrays in PHP?

  13. How to create an associative array?

  14. What is the use of isset() function?

  15. What is the use of empty() function?

  16. What is the difference between == and ===?

  17. What is a function in PHP?

  18. How do you declare a function in PHP?

  19. What is the scope of variables in PHP?

  20. What is recursion?

 

Control Structures

  1. What is an if statement?

  2. How do you write an if-else condition?

  3. What is a switch statement?

  4. What is a loop in PHP?

  5. What is a for loop?

  6. What is a while loop?

  7. What is a do-while loop?

  8. How do you stop a loop early?

  9. What is the continue keyword used for?

  10. How to loop through an array?

 

String & Array Functions

  1. How do you find the length of a string?

  2. How do you convert a string to lowercase?

  3. What is explode() in PHP?

  4. What is implode() in PHP?

  5. How do you sort an array?

  6. How do you reverse an array?

  7. How to find a value in an array?

  8. What is the use of in_array()?

  9. How do you merge two arrays?

  10. What is the difference between array_merge() and + operator?

 

Forms & User Input

  1. How do you create a form in PHP?

  2. What are GET and POST methods?

  3. What is the difference between GET and POST?

  4. How do you access form data in PHP?

  5. How do you validate form data in PHP?

  6. How do you prevent XSS in form data?

  7. How to sanitize user input?

  8. How to upload a file using PHP?

  9. What is $_FILES?

  10. How do you handle file upload errors?

 

Sessions & Cookies

  1. What is a session in PHP?

  2. How to start a session in PHP?

  3. How do you store data in a session?

  4. How do you destroy a session?

  5. What is a cookie?

  6. How do you create a cookie in PHP?

  7. How do you read a cookie in PHP?

  8. What is the difference between sessions and cookies?

  9. What are the security concerns with sessions?

  10. How to set cookie expiry time?

 

File Handling

  1. How do you read a file in PHP?

  2. How do you write to a file in PHP?

  3. What is fopen() function?

  4. What is the use of fclose()?

  5. How do you check if a file exists?

  6. What is the difference between file_get_contents() and fread()?

  7. What is the use of unlink() function?

  8. What are file modes like r, w, a?

 

Error Handling

  1. How do you handle errors in PHP?

  2. What is try-catch block in PHP?

  3. What is the difference between warning and error?

  4. What is a notice in PHP?

  5. What is the use of error_reporting()?

  6. How to log errors in a file?

 

OOP in PHP

  1. What is Object-Oriented Programming (OOP)?

  2. What is a class in PHP?

  3. What is an object?

  4. What is the __construct() function?

  5. What is inheritance in PHP?

  6. What is method overloading?

  7. What are access modifiers: public, private, protected?

  8. What is the difference between static and non-static methods?

  9. What is an abstract class?

  10. What is an interface?

 

MySQL with PHP

  1. How do you connect PHP with MySQL?

  2. What is mysqli_connect()?

  3. How do you run a query in PHP?

  4. How to insert data into MySQL using PHP?

  5. How to fetch data from MySQL using PHP?

  6. What is SQL injection?

  7. How do you prevent SQL injection?

  8. What is PDO in PHP?

  9. What is the difference between mysqli and PDO?

  10. How do you handle database errors?

 

Advanced & Miscellaneous

  1. What is Composer in PHP?

  2. What are traits in PHP?

  3. What are magic methods in PHP?

  4. What is autoload in PHP?

  5. What is the difference between include and require?

  6. What is the use of namespace in PHP?

Share: