Mostly Asked PHP Interview Question And Answer

Define PHP ?
PHP is a web language based on scripts that allows developers to dynamically create generated web pages.

How we can display text with a PHP script ?
Two methods are possible:

echo "Method 1";
print "Method 2";

How we can execute a PHP script from the command line ?
Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:
php script.php

Difference between $message and $$message ? 
$message is a simple variable whereas $$message is a reference variable. Example:
$user = 'bob'

is equivalent to

$holder = 'user';
$$holder = 'bob';

Difference between include and require function in PHP ?
The include and require statements are used to insert useful codes written in other files, in the flow of execution.
include will only produce a warning (E_WARNING) and the script will continue
require will produce a fatal error (E_COMPILE_ERROR) and stop the script

List out some PHP array function ?
Define Date() in PHP ?
The PHP date() function is used to format a time and/or date.
Various date() in PHP are-

Define cookie ?
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer.
setcookie() function is used to set a cookie.

Define session in PHP ?
A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
session_start() is used to start session

What is the main difference between PHP 4 and PHP 5?
PHP 5 includes many additional OOP (Object Oriented Programming) features than the PHP 4.