PHP Interview Questions with Answers for Freshers 2019
Question: 1. What is PHP?
Answer: PHP is a server-facet scripting language. It is the most widely used internet era to create dynamic web pages. There are many PHP based totally frameworks and Open resources available totally free to use. Some examples include WordPress, Drupal, Laravel, etc. We can embed PHP with HTML and may further write server-side code with PHP for internet improvement.
Question: 2. Which is the modern day version of PHP?
Answer: Stable launch: 7.1.4 / 13 Apr 2017; http://Hypertext Preprocessor.Net/downloads.Hypertext Preprocessor
Question: 3. What are the extensions of PHP File?
Answer: .Personal home page, .Phtml, .Php3, .Php4, .Php5, .Php7, .Phps .
Question: 4. What is the distinction among include(), include_once() and require_once()
Answer: The encompass() announcement includes and evaluates a particular line i.E. It will encompass a report primarily based in the given course. Require() does the equal component besides upon failure it’s going to generate a deadly errors and halt the script whereas consist of() will simply supply a warning and permit the script to retain. Require_once() will check if the document already has been covered and in that case it’s going to now not consist of the file again.
Question: 5. Differences among GET, POST and REQUEST strategies?
Answer: GET and POST are used to ship data from consumer browser to internet server. In case of GET, the information is despatched via the GET method in name/price pair and is URL encoded. The default GET has a limit of 512 characters. The POST technique transfers the statistics through HTTP Headers. The POST technique does no longer have any restrict in information size to be despatched. POST is used for sending records securely and ASCII and binary kind’s information. The $_REQUEST carries the content of both $_GET, $_POST and $_COOKIE.
Question: 6. Explain how PHP sends output to Browser? OR How a record is processed when it sends output to the browser?
Answer:
1. Open website http://www.Tutorialmines.Internet
2. Request despatched to a server of http://www.Tutorialmines.Net
3. Call PHP Files.
Four. PHP Scripts are loaded into memory and compiled into Zend opcode.
Five. These opcodes are executed and the HTML generated.
6. The equal HTML is sent back to Browser.
Question: 7. What are the distinct errors in PHP?
Answer: There are four basic kinds of error.
Parse Error – Commonly prompted because of syntax mistakes in codes e.G. Lacking semicolon, mismatch brackets.
Fatal Error – These are basically run time errors which are brought on whilst you try and get admission to what can’t be finished. E.G. Having access to a dead item, or looking to use a feature that hasn’t been declared.
Warning Error – These arise while u try and encompass a document that isn’t present or delete a file that isn’t on the server. This will now not halt the script; it’s going to supply the attention and retain with the following line of the script.
Notice Error – These mistakes arise while u try to use a variable that hasn’t been declared, this will no longer halt the script, It will provide the awareness and continue with the subsequent line of the script.
Question: 8. What are the diverse strategies/approaches to pass records from one net page to some other internet web page?
Answer: The one of a kind approaches to pass the information as follows:
Session
Cookie
Database
URL parameters
Question: 9. What is session and why can we use it?
Answer: The consultation is a superglobal variable that preserves information throughout subsequent pages. Session uniquely defines every person with a consultation ID, so it allows to make a customized internet utility wherein user tracking is needed.
Question: 10. What is a cookie and why can we use it?
Answer: A cookie is a small piece of statistics stored in a consumer browser. It is a technique used to perceive a person using the facts stored of their browser (if already visited that website). Using PHP we will each set and get COOKIE.
Question: 11. What characteristic can we use to locate the duration of string, and duration of the array?
Answer: For finding the length of the string we use strlen() feature and for an array, we use count number() feature.
Question: 12. What are the trends in personal home page?
Answer: These are PHP mechanisms for code re-usability to ease developers for the usage of the code in extraordinary magnificence hierarchies.
Question: 13. List out the predefined classes in PHP?
Answer:
Directory
stdClass
__PHP_Incomplete_Class
exception
php_user_filter
Question: 14. How can we change the price of a regular?
Answer: We cannot exchange the fee of a consistent.
Question: 15. What is the distinction among unset() and unlink() characteristic.
Answer: unset() is used to damage a variable while unlink() is used to wreck a record.
Question: 16. How to print the current date and time.
Answer: Get present day date and time
Question: 17. How to encrypt and decrypt the password in php?
Answer: Recommended PHP techniques are password_hash and password_verify which might be respectively used as a hashing and checking approach. MD5 turned into used earlier than however now has become obsolete.
Question: 18. What is the difference among explode() and break up() functions?
Answer: Both are used to cut up a string to an array, the basic distinction is that cut up() makes use of a sample for splitting and explode()uses a string. Explode() is quicker than break up() because it does now not suit the string primarily based on a everyday expression. Also, break up() is deprecated as of five.3.Zero. So the use of this characteristic is discouraged.
Question: 19. What is PDO instructions?
Answer: The PHP Data Objects (PDO) extension defines a lightweight, steady interface for having access to databases in PHP. It is a statistics-get admission to abstraction layer, so no matter what database we use the feature to problem queries and fetch information could be equal. Using PDO drivers we will connect with the database like DB2, Oracle, PostgreSQL, and so forth.
HubSpot Video
Question: 20. What are the Formatting and Printing Strings available in PHP?
Answer:
printf()- Displays a formatted string
sprintf()-Saves a formatted string in a variable
fprintf() -Prints a formatted string to a file
number_format()-Formats numbers as strings
Question: 21. What is the difference between javascript and PHP?
Answer: Javascript is a patron-aspect scripting language while PHP is a server-side scripting language.
Question: 22. How to get the IP deal with in Hypertext Preprocessor?
Answer: The only way is to use $_SERVER[“REMOTE_ADDR”]; but there are numerous variables like proxies, server, client, system, modern, and public that can require precise adjustments.
Question: 23. What are Constructors and Destructors?
Answer: CONSTRUCTOR: PHP allows developers to declare constructor strategies for training. Classes that have a constructor approach name this approach on each newly-created object, so it’s far appropriate for any initialization that the item may additionally want earlier than it’s far used.
DESTRUCTORS: PHP 5 introduces a destructor idea similar to that of other item-oriented languages, such as C++. The destructor technique could be known as as quickly as all references to a specific object are removed or whilst the item is explicitly destroyed or in any order in shutdown collection
Question: 24. What is the difference among ID and sophistication in CSS?
Answer: The difference among an ID and Class is that an ID may be used to pick out one element, whereas a category may be used to perceive multiple.
Question: 25. For photo work which library?
Answer: We will need to assemble PHP with the GD library of photograph features for this to paintings. GD and PHP may also require different libraries, depending on which picture formats you want to work with.
Question: 26. How do we get the current session ID?
Answer:
session_start
echo session_id;
?>
Question: 27. How do we break a session.
Answer: Destroy a consultation
PHP:
session_start;
session_destroy;
?>
Question: 28. What is an associative array?
Answer: Associative arrays are arrays that use named keys that you assign to them.
Associative array
PHP:
$capitals = array ( “India” = > “New Delhi” , “China” = > “Beijing” , “Pakistan” = > “Islamabad” ) ;
?>
Question: 29. How are we able to display and disguise an detail via jquery?
Answer: Suppose we want to show and conceal elements of a div with identity div1.
// display div
$ ( ‘#div1’ ) . Show ( ) ;
// hide div
$ ( ‘#div1’ ) . Disguise ( ) ;
Question: 30. How are we able to upload trade font length the usage of jquery?
Answer: Suppose we need to change the font length of and div with identity div1 from 12px to 18px.
Change font length the usage of jquery
JavaScript:
$ ( ‘#div1’ ) . Css ( ‘font-size’ , ’18px’ ) ;
Question: 31. How to Print Fibonacci Series in PHP?
Answer: Fibonacci series is the only in which you’ll get your subsequent term through adding previous numbers. Here is this system to print the Fibonacci Series in PHP with attempt it editor in the end to check your logical thoughts.
$num = zero ;
$a = 0 ;
$b = 1 ;
echo “
Fibonacci series for first 10 numbers:
” ;
echo $a . ‘ ‘ . $b . ‘ ‘ ;
even as ( $num < 8 )
$c = $a + $b ;
echo $c . ‘ ‘ ;
$a = $b ;
$b = $c ;
$num = $num + 1 ;
?>
Initializing first and 2nd variety as zero and 1.It’s going to print first and 2d number. Begin our loop. So third quantity could be the sum of the primary two numbers.
Question: 32. How to Print Factorial of a number of in PHP?
Answer:
$num = 5 ;
$factorial = 1 ;
for ( $i = $num ; $i >= 1 ; $i — )
$factorial = $factorial * $i ;
echo “Result is $factorial” ;
?>
Result is a hundred and twenty.
Question: 33. How to Print numbers from 1 to 10 in While loop?
Answer:
$x = 1 ;
while ( $x <= 10 )
echo “The range is: $x
” ;
$x ++ ;
?>
Question: 34. What are extraordinary worldwide variables.
Answer: The superglobal variables as follows:
$_COOKIE – It Stores all of the statistics in an associative array of variables exceeded to the modern script via HTTP Cookies.
$_GET – Send statistics to the server that is visible within the URL of the browser. It isn’t secure to ship sensitive the use of the GET approach.
$_POST – Send statistics to the server which is not seen in the URL. When the person submits the shape with the technique set because the POST Method.
$_REQUEST – Its mixed array containing values from the $_GET, $_POST and $_COOKIE global variables.
$_ENV – Get/Set an associative array of variables exceeded to the cutting-edge script via the surroundings approach…
$_FILES – Get an associative array of gadgets uploaded to the present day script via the HTTP POST technique. Used to add the record, photograph, and films, etc on the server. It contains all of the facts i.E call, extension, transient name, etc.
$_SERVER – It saves all information associated with headers, paths, and script places.
$_SESSION – It consists of consultation variables available to the modern-day script.
$GLOBALS – PHP exceptional worldwide variable that is used to get admission to global variables from everywhere within the PHP script. Contains all the global variables related to the modern script.
Question: 35. What are the blessings of PHP MySQL?
Answer: It is a strong, dependable and effective answer with superior capabilities like the following:
Data Security
On-Demand Scalability
High Performance
Round-the-clock Uptime
Comprehensive Transactional Support
Complete Workflow Control
Reduced Total Cost of Ownership
The Flexibility of Open Source