InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 101. |
How to get last inserted id after insert data from a table in mysql? |
|
Answer» 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 |
|
| 102. |
What is the difference between fopen() and fclose()? |
|||||||||
|
Answer»
These both are PHP INBUILT function which is used to open & close a FILE which is pointed file pointer.
|
||||||||||
| 103. |
How to create and destroy cookies in PHP? |
|
Answer» 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. Example 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 Cookiesetcookie("username", "", time() - 3600); |
|
| 104. |
What is the difference server side and browser side validation? |
|
Answer» 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 ValidationIn 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 ValidationIn the Client Side Validation, we can PROVIDE a better user experience by responding quickly at the browser level. |
|
| 105. |
How can we make a constant in PHP? |
|
Answer» With the HELP of DEFINE(), we can MAKE CONSTANTS in PHP. Exampledefine('DB_NAME', 'bestInterviewQ') |
|
| 106. |
What is the difference between GET & POST ? |
||||
|
Answer» These both methods are based on the HTTP method.
|
|||||
| 107. |
What is the latest version of PHP and Mysql? |
|
Answer» PHP 7.4 is the latest VERSION of PHP and 8.0 is the NEWEST version of Mysql. Also READ: Latest version PHP 7.4 Released with Advanced Features |
|
| 108. |
What are the advantages of PHP? |
| Answer» | |
| 109. |
Write a program to get second highest number in an array using PHP? |
|
Answer» Example function displaySecondHighest($arr, $arr_size) 34 |
|
| 110. |
Write a program to get LCM of two numbers using PHP? |
|
Answer» Here is the program we can use to get LCM of two number using PHP. Example// PHP program to find LCM of two numbers |
|
| 111. |
Write a program to swap two numbers using PHP. |
|
Answer» We have to use the bellow mentioned syntax to swap TWO number using PHP, with or without using the third variable. Example Without using third variable<?php ECHO "Before Swapping:"; <?php echo "Before Swapping:<br>"; |
|
| 112. |
How to send email using php script? |
|
Answer» First, create a sendEmail.php file in web document root and we have to use the below-mentioned script in it to send email using a PHP script. Change the $to_email with a RECIPIENT email address, $body and $SUBJECT as you require, and $from_email with a sender email address here. Example$to_email = "[email PROTECTED]"; |
|
| 113. |
List the different types of Print functions available in PHP? |
|
Answer» Here are the different types of PRINT FUNCTIONS available in PHP for DEVELOPERS USE:
|
|
| 114. |
What is the role of php.ini file? |
|
Answer» The php.ini FILE is a default CONFIGURATION file present in APPLICATIONS that require PHP. Developers use it to CONTROL different variables such as file timeouts, resource limits and UPLOAD sizes. |
|
| 115. |
How to remove duplicate values from array using PHP? |
|
Answer» To remove duplicate VALUES from an array using PHP, we have to use the PHP array_unique() FUNCTION. It removes duplicate values or elements from the array. If our array CONTAINS string keys, then this function will keep the FIRST encountered key for every VALUE and will ignore all other subsequent keys.Example $var = array("a"=>"best","b"=>"interview","c"=>"question","d"=>"interview"); print_r(array_unique($var)); OUTPUT Array ( [a] => best [b] => interview [c] => question) |
|
| 116. |
What is the difference between overloading and overriding in PHP? |
||||
Answer»
|
|||||
| 117. |
What is difference between __sleep and __wakeup()? |
||||||
Answer»
|
|||||||
| 118. |
What is difference between drop table and truncate table? |
||||||||||||||
Answer»
|
|||||||||||||||
| 119. |
What is 'This' key word? |
|
Answer» In PHP, the “This” keyword is a REFERENCE to a PHP object which has been created by the interpreter for the USER containing an array of variables. If “this” keyword is called inside a normal METHOD WITHIN a normal class, it RETURNS the object to the appropriate method. |
|
| 120. |
What is abstract method and abstract class? |
|
Answer» In PHP, an abstract class is ONE in which there is at least one abstract method. An abstract method is one that is DECLARED as a method but not implemented in the code as the same. Exampleabstract class PARENTCLASS { |
|
| 121. |
What is the purpose of break and continue statement? |
|
Answer» In PHP, DEVELOPERS use the break statement to TERMINATE a BLOCK and GAIN CONTROL out of the loop or switch, whereas the continue statement will not terminate the loop but promotes the loop to go to the next iteration. The break statement can be implemented in both loop (for, while do) and switch statement, but the continue statement can be only implemented in the loop (for, while do) statements. |
|
| 122. |
What is cross site scripting in PHP? |
|
Answer» Cross-Site Scripting (XSS) is one of the most common and dangerous SECURITY vulnerabilities existing within web applications. It is a MEANS to gain unauthorized access by attacking PHP scripts PRESENT in your web app. |
|
| 123. |
What is design pattern? |
|
Answer» In PHP, Design patterns are technically a description of communication between objects and classes which are customized in order to solve a common OBSTACLE related to designs in a particular context. Basically, they provide a common REUSABLE solution to everyday programming problems. Design patterns or templates help in speeding up the process of WEB development and can be USED multiple times in different scenarios as REQUIRED. |
|
| 124. |
How to increase the maximum execution time of a script in PHP? |
|
Answer» There are two ways to increase the maximum EXECUTION time of a script in PHP AVAILABLE as following. Method 1: Update php.ini fileTo complete this process, we have to OPEN the php.ini file and rearrange the max_execution_time (in SECONDS) as per our DESIRED time. Syntaxmax_execution_time = 180 //180 seconds = 3 minutes Method 2: Update .htaccess filephp_value max_execution_time 300 Method 3: Update your .php fileHere, we have to place the below-mentioned syntax on top of the PHP script. ini_set('max_execution_time', 300); |
|
| 125. |
What are default session time and path? |
|
Answer» The default SESSION time in PHP is 1440 SECONDS or 24 minutes. The default session PATH is a TEMPORARY folder/tmp. |
|
| 126. |
What are getters and setters and why are they important? |
|
Answer» In PHP, both setters and getters are methods used by DEVELOPERS to obtain or declare variables, especially the private ones. Why are they important?They are crucial because these methods ALLOW for a certain LOCATION which will be ABLE to handle before declaring it or while REVERTING it back to the developers. |
|
| 127. |
What is the difference between GROUP BY and ORDER BY? |
||||||||||
Answer»
|
|||||||||||
| 128. |
What is garbage collection in PHP? |
|
Answer» Garbage collection in PHP refers to allocating and deallocating of space due to repeated USE of a program. Many times, unnecessary space is CONSUMED when a RESOURCE is orphaned after being used. The garbage collector in PHP ENSURES that these kinds of unwanted space consumption are minimized. |
|
| 129. |
What is meant by urlencode and urldocode? |
|
Answer» In PHP, the urlencode() function is one that can be conveniently used to encode any STRING before ACTUALLY using it as PART of the URL in a query. This function is a very efficient way to pass variables onto the next page. WHEREAS, the urldecode() function is used to decode the above-encoded string into a readable format. |
|
| 130. |
How can we submit a form without a submit button? |
|
Answer» We can USE document.formname.submit() |
|
| 131. |
What is the IonCube PHP loader? |
|
Answer» The ionCube Loader is an advanced component used by developers on the SERVER to run ENCODED files. It protects the source code. When our PHP code gets pre-compiled and ENCRYPTED and requires a separate PHP module to LOAD it, ionCube PHP loader will be required at that SCENARIO. |
|
| 132. |
What is the best way to avoid email sent through PHP getting into the spam folder? |
| Answer» | |
| 133. |
What is the Apache? |
|
Answer» Apache HTTP server is the most popular OPEN source web server. Apache has been in use since the YEAR 1995. It powers more WEBSITES than any other product. |
|
| 134. |
How to redirect https to HTTP URL through .htaccess? |
|
Answer» PLACE this CODE in your htaccess file. RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
|
| 135. |
What is the difference between abstract class and interface in php? |
|
Answer» Many differences occur between the interface and abstract class in php.
Note: Our PHP logical questions has been created by seasoned PHP experts. It shall help you to ANSWER some of the most frequently ASKED questions during a job interview. |
|
| 136. |
How to write a program to make chess? |
|
Answer» Example <table width="100%" cellspacing="0PX" cellpadding="0px" border="XXX2px"> |
|
| 137. |
Write a program to display a table of any given number? |
|
Answer» Example function getTableOfGivenNumber($NUMBER) { for($i=1 ; $i<=10 ; $i++) { echo $i*$number; } } getTableOfGivenNumber(5); |
|
| 138. |
Write a program to display Reverse of any number? |
|
Answer» $NUM = 12345; echo "Reverse number of 12345 is: $revnum"; |
|
| 139. |
How can we get the browser properties using PHP? |
|
Answer» With the HELP of $_SERVER['HTTP_USER_AGENT'] |
|
| 140. |
What is a composer? |
|
Answer» It is an application package manager for the PHP programming language that provides a standard format for MANAGING dependencies of PHP software. The composer is developed by Nils Adermann and Jordi Boggiano, who continue to lead the project. The composer is easy to use, and installation can be done through the command line. It can be directly downloaded from https://getcomposer.org/download Using the composer can solve the FOLLOWING problems:
|
|
| 141. |
How to get a total number of rows available in the table? |
|
Answer» COUNT(*) is USED to count the NUMBER of ROWS in the table. SELECT COUNT(*) FROM BestPageTable; |
|
| 142. |
What is the role of a limit in a MySQL query? |
|
Answer» It is used with the SELECT STATEMENT to restrict the number of rows in the result set. Limit ACCEPTS one or two ARGUMENTS which are OFFSET and count. The syntax of limit is a SELECT name, salary FROM employee LIMIT 1, 2 |
|
| 143. |
Write a query to find the 2nd highest salary of an employee from the employee table? |
|
Answer» You can USE this SELECT MAX(SALARY) FROM employee WHERE Salary NOT IN ( SELECT Max(Salary) FROM employee); Query to find the 2nd highest salary of the employee. |
|
| 144. |
What are the final class and final method? |
|
Answer» Its properties cannot be DECLARED final, only CLASSES and methods may be declared as final. If the class or method DEFINED as final, then it cannot be extended. Exampleclass childClassname EXTENDS parentClassname { |
|
| 145. |
What is inheritance in PHP? How many types of inheritance supports PHP? |
|
Answer» Inheritance has THREE types, are given below.
But PHP supports only single inheritance, where only ONE class can be DERIVED from a single parent class. We can do the same thing as multiple inheritances by USING interfaces. Note: Before getting confused with the plethora of PHP interview QUESTIONS for experienced, 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. |
|
| 146. |
What are the different functions in sorting an array? |
|
Answer»
The items of an array can be SORTED by various methods.
|
|
| 147. |
How to remove blank spaces from the string? |
||||||||||
|
Answer» preg_replace('/\s/', '', 'Best Interview Question'); 37. What is the difference between Primary Key and Unique key?
Note: Our PHP interview QUESTIONS for freshers have been selected from a plethora of queries to help you gain valuable insights and boost your career as a PHP Developer. |
|||||||||||
| 148. |
What is the use of friend function? |
|
Answer» In PHP, a friend FUNCTION is one non-member function having access to private and protected members WITHIN a class. A friend function has the best USE case when being shared among multiple classes, which can be DECLARED either as member functions within a class or EVEN a global function. |
|
| 149. |
What is the difference between REST and Soap? |
Answer»
|
|
| 150. |
What is the difference between Apache and Tomcat? |
|
Answer» Both used to DEPLOY your Java Servlets and JSPs. APACHE is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java TECHNOLOGIES. |
|