Interview Questions PHP


1. What is PHP?
PHP stand for Hypertext Preprocessor. PHP is a Server Side Scripting Language. PHP is an Open Source Software. PHP is free to download and use. PHP scripts are executed on server. PHP supports many databases such as MYSQL, Informix, Oracle, Sybase, Solid,PostgreSQL, Generic ODBC, etc.

2. What is the method available in form submitting?

3. What are the differences between GET and POST methods in form submitting?
On the server side: 
the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.

4. What is a Session?
A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests. Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.
Code to define session in php

5. What's the difference between a cookie and session in PHP?
PHP sessions improve upon cookies because they allow web applications to store and retrieve more information than cookies.

Key difference:
Sessions store data on the server, not on the browser like cookies.
Sessions are more secure than cookies.
PHP sessions, unlike cookies which are just stored on the user's browser, need a temporary directory on the server where PHP can store the session data.
Sessions must use the session_start() function

6. How many ways we can pass the variable through the navigation between the pages?
Register the variable into the session 
Pass the variable as a cookie
Pass the variable as part of the URL

7. What are the different functions in sorting an array?

8. How can we know the total number of elements of Array?
Note: If we just pass a simple variable instead of a an array it will return 1.

9. Define PHP header() Function
The header() function sends a raw HTTP header to a client.
It is important to notice that header() must be called before any actual output is sent.

Prevent page caching:
// Date in the past
header("Expires: Mon, 26 Jul 1987 07:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");

10. How can we extract string '' from a string '' using regular _expression of php?
We can use the preg_match() function with "/.*@(.*)$/" as the regular expression pattern.

<?phppreg_match("/.*@(.*)$/","",$data); echo $data[1]; ?>