This post for newbie PHP developer who wants to enter in web development field, Here i have tried to compile The Basic PHP Interview Questions and answers for freshers (0-1year). These common php interview question and answer will help you during technical interview.

The Basic PHP Interview Questions and answers for freshers.

Question: 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.

Question: In how many ways you can embed PHP code in an HTML page?

below are the markup tags ate are recognised by the PHP Parser.

<?php Write php code here ?>
<?    Write php code here ?>
<?=   Write php code here ?>

Question: Is PHP a case sensitive language?

No, PHP is partially case sensitive.

Question: How to convert array to string in php?

$array = array('cakephp','zend');
$string =implode(' and ',$array);
echo $string;

Question: How to connect mysqli with php using Procedural Way?

$host = "localhost";
$username = "root";
$password = "";
$conn = mysqli_connect($host, $username, $password);
//connect to server
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
echo "Connected successfully";

Question: How to connect mysqli with php using Object-Oriented Way?

$host = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($host, $username, $password);
//connect to server
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
echo "Connected successfully";

Question: How to connect mysqli with php using PDO?

$host = "localhost";
$username = "root";
$password = "";
 $conn = new PDO("mysql:host=$host;dbname=myDB", $username, $password);
// set the PDO error mode to exception
echo "Connected successfully";

Question: How will you define a constant in PHP?

To define a constant you have to use define() function and to retrieve the value of a constant, you have to simply specifying its name. Unlike with variables, you do not need to have a constant with a $.

Question: What is meant by nl2br()?

Inserts HTML line breaks before all newlines in a string.

Question: How can we know the total number of elements of Array?

If we just pass a simple var instead of a an array it will return 1.

Question: What are the Different Types of database in Mysql?

There are Five Types of database in Mysql

Question: How can we set and destroy the cookie in php?

By using setcookie(name, value, expire, path, domain); function we can set the cookie in php ;
Set the cookies in past for destroy. like
setcookie(“user”, “sonia”, time()+3600); for set the cookie
setcookie(“user”, “”, time()-3600); for destroy or delete the cookies;

Question: What are PHP magic constants?

PHP provides a large number of predefined constants to any script which it runs known as magic constants.

Question: What is the purpose of break statement?

break terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.

Question: What is the syntax for ‘foreach’ loop.

he foreach loop works only on arrays, and is used to loop through each key/value pair in an array.

foreach ($array as $value) {
    code to be executed;

Question: How to destroy/unset one session?


Question: How to Destroys all data registered to a session?


Question: How to convert string to uppercase in php?

$string="my public notebook";
echo strtoupper($string);

Question: How to convert string to lowercase in php?

echo strtolower($string);
//Output: my public notebook

Question: Difference between array_merge and array_combine in php?

Example-1: array_merge

$array1 = array('one','two');
$array2 = array(1,2);
$result = array_merge($array1,$array2);

Example-2: array_combine

$array1 = array('one','two');
$array2 = array(1,2);
$result = array_combine($array1,$array2);

Question: How to get ip address in php?


Question: What is the purpse $_PHP_SELF variable?

The PHP default variable $_PHP_SELF is used for the PHP script name and when you click “submit” button then same PHP script will be called.

Question: How will you redirect a page using PHP?

Using header function in php


Question: How can we define constants in PHP?

//define constant 
// use constant

If You have more question and answer for 0-1year newbie developer then you can post these questions and answers in the comment box and help new comers.

If you like this post please don’t forget to subscribe my public notebook for more useful stuff