Tags:

PHP-MySQL Interview Questions and Answers : Most Common Questions

By Dhananjay yadav January 19, 2018


There are some basic PHP Interview questions, asked in every interview often. They must be known to every interview aspirants. Chances of asking these questions by Interviewer is very high because they just test your basic concepts of PHP.They highlight your understanding and command of the language. They are helpful to nail the first impression on interviewer when you are in the interview. An Interviewer expects that you should know the answers to these questions. After these questions, you will be asked to answer some hard-core questions and concepts. What we have given here is experienced. these questions give you the pattern of often asked question on Interview along with their answers. We try to give genuine answers, by verifying them from www.php.net, www.w3schools.com, and other popular tutorials site. After knowing the pattern It will be easy for you to explore more questions from various sources.


What is PHP ?
PHP is a server-side scripting language. It is lightweight as well as enriched with OOPs features. PHP is freely available and has lots of frameworks, CMS to built robust and secure applications.

Explain these functions :
echo( ),print( ),print_r( ),die( ),exit( ),var_dump( )
var_dump($var):- Displays information about a variable.
echo() or echo: This is not actually a function.This doesn't return a value after it takes parameter.
print() pritn : This is also not a function ,accepts always single parameter and returns 1.
print_r():-This prints the content and indexes of arrays and objects.
exit:-It terminates the current script with a message.
die(): This is identical to exit;

What are the differences amongst include(), require(),require_once(), require(),include()?
include(): Includes an external script into current script. On failure it emits Warning and allows script to continue, it does not terminate the execution of the script.
include_once(): On failure emits an compile E_COMPILE_ERROR  error. It terminates the script execution.

What is the difference between in_array() and is_array()?
Both of these function returns a boolean type.
in_array() :
If a value finds within an array it returns TRUE otherwise returns false.
is_array() :
It checks whether the type of variable is an array or not. It returns true if an array is passed into it. It can be applied to any type of array.

What is the difference between count() and sizeof()?
Literally we can say there is no difference between these two terms. Both of these have Identical behaviors.
count():- It counts all elements of an array or object.
sizeof():-Identical to count(), can say Alias.

What is the difference between json_encode() and json_decode()?
json_encode() converts a PHP array or an object into json string, and json_decode() convers an JSON string into PHP array or into PHP object.

Where do we store Session and Cookie?
The session is stored on server whereas cookies are stored on the client machine in browsers.

How we use foreach loop in PHP?
Foreach loop is used to iterate an array or an object in PHP . For example

<?php 
foreach ($array as $key =>; $value){
echo "$value is at $key place";
}
?>

What are the differences amongst trim(),ltrim(),rtrim()?
  • trim():-It removes white spaces from both the sides of a string.
  • ltrim():-It removes white space from left side of a string.
  • rtrim():-It removes white space from right side of a string.
What are the constants , how we define them in PHP?
A constant is a name assigned to a value. It is like Identifiers but cannot change during script execution. We can define them usually in UPPER_CASE underscored string without $. For example: define("CURRENT_YEAR", "2017");

What is $_GLOBAL?
$_GLOBAL Is a superglobal array and holds all the variables that are global and can be accessible from anywhere in the script. $_POST,$_GET,$_REQUEST,$_FILE,$_SESSION,$_COOKIE all are superglobal arrays available in PHP. We can call them anywhere in the script.

What is the difference between MySQL and mysqli?
MySQLi is the extension of MySQL and It is an improved version of MySQL. MySQLi supports OOPS features and compatible to PDO.

What unlink() function do in PHP?
It is used to delete a file or directory from its location.

What are the basic differences amongst Warning, Fatal Error, and Notice?
Fatal error results in the termination of script, No further execution of the script is possible when it happens. Whereas Notice does not terminate the script, rather it notifies about some tolerable mistake and script after that line is able to execute. Warnings are the deprecated and bearable things in scripts. The doesn't affect the result usually.

What is the difference between array_diff() and array_filter()?
array_diff() returns the array of values of difference of two arrays and array_filter() returns the arrays of values and filter null values or specific values. The function array_filter() also used a callback function but it is optional.

What is the difference between array_serach() and in_array()?
The method array_search() returns the key if the value is found in the array and the function in_array() return TRUE if it will find the values in the array. In case of a failure, both functions return FALSE.

What strlen() do?
strlen() is a PHP library function and it returns the length of string passed to it.

How substr() works?
substr() is a PHP library function and it returns the part of string passed with parameters to it. It accepts starting point, length of returning string and input string as parameters.

How str_replace() works?
It is used to replace a sub-string with another substring in an input string.

Post Tags:

No Comment to " PHP-MySQL Interview Questions and Answers : Most Common Questions "