Interview Questions on PHP

In this post, we will discuss interview questions on PHP. These questions may be helpful for interviews at every level.

Interview questions on PHP
Interview questions on PHP
Interview Questions on PHP

Question1. What are the Implode and Explode functions?

Answer:  implode:-returns a string from elements of an array.
echo implode(” “,$arr);
ans-hello world! beautiful day!

explode function:-it breaks a string into array.
$str=”hello world. it’s a beautiful day.”:
print_r(explode(” “,$str):

$pizza = “piece1 piece2 piece3 piece4 piece5 piece6″;
$pieces = explode(” “, $pizza);
echo $pieces[0];
echo $pieces[1];
echo $pieces[2];
echo $pieces[3];
echo $pieces[4];
echo $pieces[5]

echo $pieces[6];

Question2. How to register the variables into a Session?

Answer: The variable is registered into a Session by using session_register function.


Question3. What are the different types of Errors in PHP?

Answer: here are four basic types of runtime errors in PHP:

1. Notices: These are trivial, non-critical errors that PHP
encounters while executing a script – for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all – although you can change this default behavior.

  1. Fatal errors: These are critical errors – for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.
  2. Warnings: These are more serious errors – for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.4. Parse Error: When we make mistake in PHP code like missing semicolon or any unexpected symbol in code.

Question4: How to optimize or increase the speed of a MySQL select query?

Answer: To increase the speed of select query, there are some factors-
-By using Proper Index on table

-By using Limit in the query
-By using Primary key

Whenever the huge number of updation or deletion happened in the table  OPTIMIZE TABLE command is used. This will reduce the unused space.

Question5. Define Type Juggling?

Answer: type juggling is one of the features of PHP, provided, to deal with PHP variables. PHP is a loosely typed language, and hence, capable of taking the data type of the value, as that of the variable, to which that value is assigned.

If we initialize a variable with an integer value, then PHP evaluates the type of the variable as an integer based on its value. Similarly, if it is a string value, then the same for the variable as well

For Example- $var3= $var1 + $var2.

If the $var1 is an integer. $var2 and $var3 will also be treated as integers.

Question6. How to insert javascript in PHP code?

Answer:    <?php
echo”<script language=’javascript’>



some php code…

<script type=”text/javascript”>
function some Fun()
function code….

some php code…

Question7: How to count the number of parameters given in a URL by POST method?

Answer:  count() function can be used for this.

count counts the number and $_POST gets all the values which are posted in the form.

Question8: How to get a user’s IP address?

Answer:  We can get the visitor’s/client’s IP address is using the $_SERVER[‘REMOTE_ADDR’] or $_SERVER[‘REMOTE_HOST’] variables.


$_SERVER[‘REMOTE_ADDR’] – Returns the IP address of the user from which viewing the current page.

echo ‘User IP – ‘.$_SERVER[‘REMOTE_ADDR’];


Question9: What is the difference between include() and require()?

Answer:  The content of a file can be inserted into a PHP file before the server executes it, with the include() or require() function.
The two functions are identical in every way, except errors handling.
The include() function, generates a warning but the script will continue execution.

while require() function generates a fatal error and the script execution will stop after the error.


Question10:  How to set the browser timeout?

Answer: The browser timeout is the number of seconds a script is allowed to run has to be set.

– If this limit is reached, the script returns a fatal error.

The set_time_limit(), restarts the timeout counter from zero.

Example: set_time_limit(600);

timeout to 600 seconds or 10 minutes.

Follow us on:

Spread the knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *