PHP technical interview questions and answers are essential for candidates preparing for web development roles. PHP powers millions of websites and content management systems, so companies often evaluate your knowledge of syntax, arrays, sessions, cookies, form handling, OOP concepts, and database connectivity. Popular companies like TCS, Wipro, Infosys, Capgemini, Cognizant, and Accenture regularly include PHP questions in coding rounds and technical interviews. This guide explains the most frequently asked PHP interview questions with simple examples and clear definitions. Whether you are a fresher preparing for campus placements or an experienced developer, these questions will help you understand PHP concepts better. You can also download PHP interview PDFs and practice mock questions for better preparation.
21. What is the difference between mysql_fetch_object and mysql_fetch_array?
MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array
22. How can I execute a PHP script using command line?
Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.
23. I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, whats the problem?
PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.
24. How do you pass a variable by Refernce?
Just like in C++, put an ampersand in front of it, like $a = &$b
25. How do I find out the number of parameters passed into function9. ?
func_num_args() function returns the number of parameters passed in.
26. If the variable $a is equal to 5 and variable $b is equal to character a, whats the value of $$b?
5, Its a reference to existing variable.
27. What are the differences between DROP a table and TRUNCATE a table?
DROP TABLE table_name This will delete the table and its data.
TRUNCATE TABLE table_name This will delete the data of the table, but not the table definition.
28. Why doesnt the following code print the newline properly?
Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters \ and n.
29. Would you initialize your strings with single quotes or double quotes?
Since the data inside the single-quoted string is not parsed for variable substitution, Its always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.
30. What is the difference between the functions unlink and unset?
unlink() is a function for file system handling. It will simply delete the file in context.
unset() is a function for variable management. It will make a variable undefined.