YouTube Icon

Interview Questions.

PHP Interview Questions and Answers for Freshers 2019 - Jul 15, 2022

fluid

PHP Interview Questions and Answers for Freshers 2019

Q1. What is PHP?

Ans: 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.

Q2. Which is the modern day version of PHP?

Ans: Stable launch‎: ‎7.1.4 / 13 Apr 2017; http://Hypertext Preprocessor.Net/downloads.Hypertext Preprocessor

Q3. What are the extensions of PHP File?

Ans: .Personal home page, .Phtml, .Php3, .Php4, .Php5, .Php7, .Phps  .

Q4. What is the distinction among include(), include_once()  and require_once()

Ans: 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.

Q5. Differences among GET, POST and REQUEST strategies?

Ans: 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.

Q6. Explain how PHP sends output to Browser? OR How a record is processed when it sends output to the browser?

Ans:

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.

Q7. What are the distinct errors in PHP?

Ans: 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.

Q8. What are the diverse strategies/approaches to pass records from one net page to some other internet web page?

Ans: The one of a kind approaches to pass the information as follows:

Session

Cookie

Database

URL parameters

Q9. What is session and why can we use it?

Ans: 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.

Q10. What is a cookie and why can we use it?

Ans: 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.

Q11. What characteristic can we use to locate the duration of string, and duration of the array?

Ans: For finding the length of the string we use strlen() feature and for an array, we use count number() feature.

Q12. What are the trends in personal home page?

Ans: These are PHP mechanisms for code re-usability to ease developers for the usage of the code in extraordinary magnificence hierarchies.

Q13. List out the predefined classes in PHP?

Ans:

Directory

stdClass

__PHP_Incomplete_Class

exception

php_user_filter

Q14. How can we change the price of a regular?

Ans: We cannot exchange the fee of a consistent.

Q15. What is the distinction among unset() and unlink() characteristic.

Ans: unset() is used to damage a variable while unlink() is used to wreck a record.

Q16. How to print the current date and time.

Ans: Get present day date and time

<?Php echo date ( 'Y-m-d H:i:s' ) ; ?>

 

Q17. How to encrypt and decrypt the password in php?

 

Ans: 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.
 

Q18. What is the difference among explode() and break up() functions?

Ans: 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.

Q19. What is PDO instructions?

Ans: 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
 

Q20. What are the Formatting and Printing Strings available in PHP?

Ans:

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

Q21. What is the difference between javascript and PHP?

Ans: Javascript is a patron-aspect scripting language while PHP is a server-side scripting language.

Q22. How to get the IP deal with in Hypertext Preprocessor?

Ans: 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.

Q23. What are Constructors and Destructors?

Ans: 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

Q24. What is the difference among ID and sophistication in CSS?

Ans: 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.

Q25. For photo work which library?

Ans: 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.

Q26. How do we get the current session ID?

Ans: <?Php

session_start

echo session_id;

?>

Q27. How do we break a session.

Ans: Destroy a consultation

PHP:

<?Php

session_start;

session_destroy;

?>

Q28. What is an associative array?

Ans: Associative arrays are arrays that use named keys that you assign to them.

Associative array

PHP:

<?Php

$capitals = array ( "India" = > "New Delhi" , "China" = > "Beijing" , "Pakistan" = > "Islamabad" ) ;

?>

 

Q29. How are we able to display and disguise an detail via jquery?

 

Ans: Suppose we want to show and conceal elements of a div with identity div1.

// display div

$ ( '#div1' ) . Show ( ) ;

// hide div

$ ( '#div1' ) . Disguise ( ) ;

 

Q30. How are we able to upload trade font length the usage of jquery?

Ans: 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' ) ;

 

Q31. How to Print Fibonacci Series in PHP?

 

Ans: 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.

<?Php   

$num = zero ;   

$a = 0 ;   

$b = 1 ;   

echo "<h3>Fibonacci series for first 10 numbers: </h3>" ;   

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.

 

Q32. How to Print Factorial of a number of in PHP?

 

Ans:

<?Php   

$num = 5 ;   

$factorial = 1 ;   

for ( $i = $num ; $i >= 1 ; $i -- )   

   

   $factorial = $factorial * $i ;   

   

echo "Result is $factorial" ;   

?>   

Result is a hundred and twenty.

 

Q33. How to Print numbers from 1 to 10 in While loop?

Ans:

<?Hypertext Preprocessor

$x = 1 ;

 

while ( $x <= 10 ) 

echo "The range is: $x <br>" ;

$x ++ ;

?>

Q34. What are extraordinary worldwide variables.

Ans: 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.

Q35. What are the blessings of PHP MySQL?

Ans: 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




CFG