PHP Interview Questions and Answers

PHP originally derived from Personal Home Page Tools, now stands for Hypertext Preprocessor. It is a open source server side scripting language designed for web development. It is fast, flexible and pragmatic programming language used for most popular websites.


11) What is the output of the following code?

<?php

$a = '1';

$b = &$a;

$b = "2$b";

echo $a.", ".$b;

?>


12) How can you enable error reporting in PHP?

Check if display_errors is equal “on” in the php.ini or declare “ini_set('display_errors', 1) in your script.
Then, include error_reporting(E_ALL) in your code to display all types of error messages during the script execution.


13) Can the value of a constant change during the script’s execution?

No, the value of a constant cannot be changed once it’s declared during the PHP execution.


14) What does the following code output?

<?php

$i = 016;

echo $i / 2;

?>


15) How stop the execution of a php script ?

By using exit() or die() we can stop execution oh a PHP script.


16) How to redirect a page in php?

The following code can be used for it, header(“Location:index.php”);


17) How to declare an array in php?

Array Declaration: 

var $arr = array(‘apple’, ‘grape’, ‘lemon’);


18) What is use of in_array() function in php ?

in_array() function used to checks if a value exists in an array.


19) What’s the difference between include and require?

It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.


20) What types of loops exist in php?

There are  different types of loops in php : for,while,do while and foreach (NB: You should learn its usage).