PHP Interview Questions and Answers
PHP earlier stood for Personal Home Pages, but now it stands for Hypertext Pre-processor. PHP is a server-side scripting language that is used for building web pages and applications. We have just added more questions in our question bank for PHP interview questions. This language includes many Frameworks and CMS for creating large websites. Even a non-technical person can create web pages or apps using PHP CMS or frameworks. PHP supports various frameworks and CMS that are used to develop applications.
Before getting confused with the plethora of PHP developer interview questions, you need to ensure the basics. This question will help you to understand the core basics of PHP and make you even more confident enough to jump onto the advanced questions.
Quick Facts About PHP | |
---|---|
What is the latest version of PHP? | 8.0.3, released on 4th March 2021 |
Who is the developer of PHP? | Rasmus Lerdorf |
What language does PHP use? | C language |
PHP License | It is a BSD-style license which does not have the "copyleft" and restrictions associated with GPL. |
- It runs on various platforms, including Windows, Mac OS X, Linux, Unix, etc.
- It is compatible with almost all servers, including Apache and IIS.
- It supports many databases like MySQL, MongoDB, etc
- It is free, easy to learn and runs on the server-side.
- PHP can operate various file operations on the server
Note: This is a list of the most frequently asked PHP interview questions. Please have a good read and if you want to download it, it is available in a PDF format so that you can brush up your theoretical skills on this subject.
Top PHP Developer Interview Questions
function displaySecondHighest($arr, $arr_size)
{
if ($arr_size < 2)
{
echo(" Invalid Input ");
return;
}
$first = $second = PHP_INT_MIN;
for ($i = 0; $i < $arr_size ; $i++)
{
if ($arr[$i] > $first)
{
$second = $first;
$first = $arr[$i];
} else if ($arr[$i] > $second &&
$arr[$i] != $first)
$second = $arr[$i];
}
if ($second == PHP_INT_MIN)
echo("There is no second largest element\n");
else
echo("The second largest element is " . $second . "\n");
}
// Here is your Array
$arr = array(12, 35, 1, 10, 34, 1);
$n = sizeof($arr);
displaySecondHighest($arr, $n);
Output:
34
- Open source
- Robust functions
- Centralized built-in database
- Extensive community support
PHP 7.4 is the latest version of PHP and 8.0 is the newest version of Mysql.
These both methods are based on the HTTP method.
GET | POST |
---|---|
The GET method transfers data in the form of QUERY_STRING. Using GET it provides a $_GET associative array to access data | The post method transfer form data by HTTP Headers. This POST method does not have any restrictions on data size to be sent. With POST method data can travel within the form of ASCII as well as binary data. Using POST, it provides a $_POST associative array to access data. |
With the help of define(), we can make constants in PHP.
define('DB_NAME', 'bestInterviewQ')
We need to add validation rules while making web forms. It is used because we need to take inputs from the user in the right way like we need the right email address in the email input field. Some time user did not enter the correct address as we aspect. That's why we need validation.
Validations can be applied on the server side or the client side.
Server Side Validation
In the Server Side Validation, the input submitted by the user is being sent to the server and validated using one of the server-side scripting languages like ASP.Net, PHP, etc.
Client Side Validation
In the Client Side Validation, we can provide a better user experience by responding quickly at the browser level.
A cookie is a small file that stores on user's browsers. It is used to store users information. We can create and retrieve cookie values in PHP.
A cookie can be created with the setcookie()
function in PHP.
Create Cookie
$cookie_name = "username";
$cookie_value = "Umesh Singh";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
Update Cookie
$cookie_name = "username";
$cookie_value = "Alex Porter";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
Delete Cookie
setcookie("username", "", time() - 3600);
These both are PHP inbuilt function which is used to open & close a file which is pointed file pointer.
S.no | fopen() | fclose() |
---|---|---|
1. | This method is used to open a file in PHP. | This method is used to close a file in PHP. It returns true or false on success or failure. |
2. | $myfile = fopen("index.php", "r") or die("Unable to open file!"); |
$myfile = fopen("index.php", "r"); |
mysql_insert_id()
is used to get last insert id. It is used after insert data query. It will work when id is enabled as AUTO INCREMENT
It is used to replaces some characters with some other characters in a string.
Suppose, we want to Replace the characters "Umesh" in the string "Umesh Singh" with "Sonu"
echo str_replace("Umesh","Sonu","Umesh Singh");
Top 10 PHP Interview Questions
Here you will find the list of Top PHP interview questions, which were written under the supervision of industry experts. These are the most common questions and usually asked in every interview for the role of the PHP Developers.
- What are Design Patterns in PHP?
- What is the difference between abstract class & interface in PHP.
- What is traits & how it can we used?
- What is the use of .htaccess file?
- What is the difference between MyISAM and InnoDB?
- What is the difference between Public Private and Protected?
- What is Constructor and Destructor?
- What is final class and final method in PHP?
- What is a static member function?
- What is function Overloading and Overriding in PHP?