Advanced PHP Interview Questions and Answers

What is PHP?

PHP, called as Hypertext Preprocessor Language is one of the widely used server side scripting language that is designed for web development. It was created by Rasmus Lerdorf in the year 1994. Its code is embedded into HTML or the language can also be used in combination of different web template systems and web frameworks. Much of its syntax is borrowed from C, JAVA and PERL with few of its specific features. 

Benefits of PHP:

PHP Interview Questions and AnswersThough its name Hypertext Preprocessor, the first word confuses many people. “Hypertext”, is the word of acronym otherwise called as recursive acronym. Using PHP you need not use lot of commands unlike HTML. It just contains HTML with embedded code that is enclosed with special starting and ending processing instructions. These commands allow you to jump into and out of PHP mode.

This section holds the best things about PHP: 
  • The code is executed on the server, generating HTML which is then sent to the client. This feature distinguishes PHP from client side JAVA script. 
  • This language is extremely simple for a new comer and also offers advanced features for a professional programmer. 
  • Try to learn the maximum number of PHP features because it helps you start writing simple scripts in few hours. 

What is the Future of PHP for Web Development?

Are you planning to proceed and work on PHP? Worried about the scope of PHP in future? Yes! At current market, we can assure an excellent future through PHP. However, none of the technology is permanent and constant in this technical era. But, to choose a better option for now, it is the best one to start with. 

Some of these points would clear you the future scope of PHP for those who are about to choose this platform and for those who are working on it as well. 

  • There is vast availability of PHP applications on internet that make you think about its popularity. For example, today when you start surfing the net, you can easily find out many websites with the extension .PHP. 
  • Pages created using PHP are considered to be a common part of web applications. It is one of the most popular languages for web development used by developers all over the world. 
  • Millions of websites all over the world are built using PHP and my SQL. 
  • As blogs are the most content sources of internet today, people with minimum technical language knowledge can operate them by simple language like PHP. 
  • PHP is always easy and simple to use. Hence working with it makes your future bright as other languages are more complex compared to this language. 
  • There are many frameworks that are coming into existence to support this language. This indicates the measure for PHP future. 

PHP Interview Questions and Answers:


Following are the Core PHP Interview Questions you are asked during the interview. Take some time to read the answers before attending your interview. 

1) What is PHP? 

PHP, a server side scripting language has many frameworks and is commonly used for web applications. You need not be a technical person to learn PHP. Even a non – technical person can create his/her own websites using its CMS. Just like Java, it is also an object an oriented programming language and is very easy to learn. 

2) What is the use of the word ‘print’ in PHP? 

Print is a language construct and is not actually a real function. Use it without parentheses with its argument list. 

For example: print(‘PHP Important Questions’);

3) What is count() function in PHP?

count() function is used to count all the elements in an array or in an object. 

4) What is the difference between include and require? 

The include() function takes up all the text from a specified file and copy the text into the file that uses the include() function. The require() also takes up the text from a specified file and copy the text into files that uses the include function. But the difference is that in include() function, if there is any problem in loading the file, then the function a warning but the execution continues unlike require function. 

5) Difference between Session and Cookie? 

The most important difference between sessions and cookies is that sessions are generally stored on the server whereas cookies are stored on the user’s computers in the form of text file. 

The other different is that cookies can hold multiple variables, whereas session remains to be active as long as browser is opened. 

Sessions are mostly used for login / logout purposes, but cookies are used for user activity tracking. 

6) How can you set cookies in PHP? 

Setcookie(“Sample”, John”, time()+3600); 

7) How can you view a cookie value? 

Echo $_COOKIE[“user’]; 

8) How can you create and set a value in session? How can you remove data from a session? 

Create session : session_start();

Set value to session : $_SESSION[‘USER_ID’]=1;

Remove data from a session : unset($_SESSION[‘USER_ID]); 

9) What are the types of loops in PHP? 

For, while, do while and for each. (Try to learn its usage). 

10) How can you create mysql connection? 

Mysql_connect(servername, username, password); 

11) A program using while loop? 

$my_query = mysql_query(“SELECT *FROM ‘users’ WHERE ‘u_id’=’1’;”);

While($result = mysql_fetch_array($my_query))

{

Echo $result[‘Firstname’.].”<br>”;


12) What is difference between explode() and split()? 

Explode function splits a string into array using a string. But the split function splits string into array using regular expression. 

13) What is the usage of mysql_real_escape_string() function? 

It is used to make the special characters escaped in a string for use in an SQL statement. 

14) Can you write code for “Save an uploaded file in PHP”? 

If($_FILES[“file”][“error”] == 0)

{

Move_uploaded_file($_FILES[“file”][“tmp_name”], upload/”. $_FILES[“file][“name”];

Echo “Stored in:” . “upload/” .$_FILES[“file”][“name”];


15) How can you strip whitespace or even the other characters from the beginning and end of a string? 

Trim() function removes whitespaces or any other characters from both sides of a string.
Advanced PHP Interview Questions and Answers Advanced PHP Interview Questions and Answers Reviewed by amara sangati for Rating: 5