PHP Interview Questions and Answers

What is PHP?
The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.
What are the differences between Get and post methods?
There are some defference between GET and POST method 1. GET Method have some limit like only 2Kb data able to send for request But in POST method unlimited data can we send 2. when we use GET method requested data show in url but Not in POST method so POST method is good for send sensetive request
What are the differences between require and include?
Both include and require used to include a file but when included file not found Include send Warning where as Require send Fatal Error .
What is use of header() function in php ?

The header() function sends a raw HTTP header to a client.We can use header() 
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen.

What is meant by nl2br()?

Inserts HTML line breaks (<BR />) before all newlines in a strin

How we get IP address of client, previous reference page etc ?
By using $_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_REFERER'] etc.
How can we register the variables into a session?
$_SESSION['name'] = 'me';

What are the different types of error in php?

three 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.

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.

3. 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 
default behavior is to display them to the user when they take place.

Latest Updates

Height and Distance

An aeroplane flying at a height of 300 m above the ground passes vertically above another plane at an instant when the angles of elevation of the two planes from the same point on the ground are 60º and 45º respectively. What is the height of the lower plane from the ground?

From the top of a building 90 m high, the angles of depression of the top and the bottom of a tree are 30º and 45º respectively. What is the height of the tree?

Trigonometry

What is the value of sinx √( 1 /1+cosx + 1 /1-cosx ) ?

What is cos4 A - sin4 A / cos2 A - sin2 A equal to?

If 7sin2 x +3cos2 x = 4, 0 < x < 90º ,then what is the value of tan x?

If x = a cosθ + b sinθ and y = a sinθ - b cosθ then what is x2 + y2 equal to?

Average

The mean of 5 numbers is 15. If one more number is included, the mean of the 6 numbers becomes 17. What is the included number?

The mean marks obtained by 300 students in a subject are 60. The mean of top 100 students was found to be 80 and the mean of last 100 students was found to be 50. The mean marks of the remaining 100 students are?

In an asymmetrical distribution, of the mean and median of the distribution are 270 and 220 respectively, then the mode of the data is?

Let a, b, c, d, e, f, g be consecutive even numbers and j, k, l, m, n be consecutive odd numbers. What is the average of all the numbers?

Alligation or Mixture

25 kg of alloy X is mixed with 125 kg of alloy Y. If the amount of lead and tin in the alloy X is the ratio 1 : 2 and the amount of lead and tin in the alloy Y is in the ratio 2 : 3, then what is the ratio of lead to tin in the mixture?

Simplification

The ratio of two numbers is 1 : 5 and their product is 320. What is the difference between the square of these two numbers?

Trigonometry

What is the value of cot 4π/3 ?

Indian Politics

Article-24 of the Indian Constitution ‘Prohibition of employment of children in factories, etc’ deals with?

Article-134A of the Indian Constitution ‘Certificate for appeal to the Supreme Court’ deals with?

Chemistry

Who invented Aspirin?

Physics

A larger force on a rotating body results in larger?

What is the unit of the physical quantity, magnetic flux density?