Top 10 Frequently asked Interview Questions (With Answers) for PHP.

If you are preparing for an interview for PHP, have a look at the questions down below to up your confidence during the interview.

1) What are the differences between echo and print in PHP?

Ans: The only differences between the two are as follows-

a) echo does not return a value whereas print does return a value of 1

b) echo can accept multiple parameters while print can take only a single argument.

2) What is the use of the header()function in PHP?

Ans: The header() function is used to:

a) redirect from one page to another

b) send an HTTP status code

c) send a raw HTTP header

3) Can you extend a  Final defined class?

Ans: No, you cannot extend Final defined class.

4) What are the three scope levels in PHP and how can you define them?

Ans: The three scope levels in PHP are as follows-

a) Private– Visible only in its own class
b) Public– Visible to any other code accessing the class
c) Protected– Visible only to classes parent(s) and classes that extend the current class.

5) What is the difference between a session and cookies?

Ans: A session stores the value on the server whereas, cookies store the value in the user’s browser.

6) What are traits?

Ans: Traits are a mechanism of code inclusion or code re-usability. A trait cannot be instantiated on its own.

7) How can be get the number of elements in an array?

Ans: The count() function is used to return the number of elements in an array.

8) What are the uses of explode() and implode() functions?

Ans: explode() function is used to split a string into an array and implode() function is used to make a string by combining the array elements.

9) Which function in PHP is used to check the data type of any variable?

Ans: gettype() function is used to check the data type of any variable.

10) Which function is used in PHP to search a particular value in an array?

Ans: in_array() function is used to search a particular value in an array.

Additional Questions

1) Which function in PHP is used to delete a file?

Ans: unlink() function is used in PHP to delete a file.

2) Which programming language does PHP resemble?

Ans: PHP syntax resembles Perl and C

3) How to check if a given variable is empty?

Ans: empty() function is used to check if a given variable is empty or not.

4) Is it possible to remove the HTML tags from data?

Ans: strip_tags() function enables us to clean a string from HTMl tags.

5) In PHP, are objects passed by value or reference?

Ans: In PHP, objects are passed by vale.

Hope these questions helped solved your uncertainty for your interview. Comment down below your thoughts!

Leave a Reply

Your email address will not be published.