100+ PHP Interview Questions Answers for Freshers 2017

100+ PHP Interview Questions for Freshers 2017 – In this list I am sharing the top asked 100+ interview questions with answers for php freshers who will going for a job interview as junior PHP developer/ programmer.

What is the PHP?
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

What is a PHP developer do?
PHP developers develop programs, applications, and web sites using the dynamic scripting language PHP. PHP is known for web development and business applications. Depending on job function, PHP developers may be classified as software developers or web developers.

What is the meaning of hypertext preprocessor?
While PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor, which is a recursive backronym. PHP code can be simply mixed with HTML code, or it can be used in combination with various templating engines and web frameworks.

Why the PHP is called hypertext?
“PHP/FI” was also another name for PHP. php is called hypertext preprocessor as its libraries are already compiled.when any person request for any php page in the address bar of the browser that request is first sent to the server then server interpret php files and return back response in form of Html.

Top best php interview questions answers for freshers 2017 – Topics included are php, mysql, javascript, html, css, jquery.

Tell something about PHP.

PHP stands for: Hypertext Preprocessor. PHP is a server side scripting language which is used to develop the dynamic websites.

Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.

To concatenate two string variables together, use the dot (.) operator.

<?php
$string1="Hello World";
$string2="1234";
echo $string1 . " " . $string2;
?>

This will produce following result −

Hello World 1234
What is MVC?

MVC stands for Model, View, and Controller. PHP MVC is an effective way to manage the code into 3 different layers.
Model: Model represents the information in application.
View: View represents the visual representation of information and data that you have entered in the application.
Controller: Controller is actually how and in which way you want to read the information in application.

What are the different types of CSS you can add in a page?

There are three types of CSS that can be added in a page.

  • External CSS.
  • Internal CSS.
  • Inline CSS.
Does PHP support multiple inheritances?

No, PHP support only single level of inheritance. A class can be inherited from a single class using keyword ‘extended’.

What is the difference between echo and print?

Initially both look same because both used to display any value. Main difference between echo and print is that echo is just used to display any string in output. It will display whatever is passed to it but on other hand print is a function itself it not only display any value but also can return value.

What is the difference between GET and POST method?

Whenever we fill any form on internet we can used one from two methods to send data on sever computer, that method can be either GET or POST. When we use the GET method all information is displayed on address bar. If can sent up to 1024 of data using GET method so it is good to use only when we are working with small scale applications and data is not that much sensitive. If we talk about POST method, No information will be displayed on address bar and we can send up to 2 mb of data using POST method. This limit can also extend further if required. PHP includes many CMS systems which can be used to handle the web content in a effective way.

What functions are used to get the image size, Width and Height?

getimagesize () to get the size of an image
Imagesx () to get width of an image
Imagesy () to get height of an image.

What is PEAR in PHP?

PEAR stands for “PHP Extension and Application Repository”. PEAR provides an inbuilt library of open source code for PHP developers. It provides support for package maintains and code distribution.

How do you upload videos using PHP & MySQL?

We just need to copy the path of stored videos in the database rather than storing the videos files itself. All videos will be saved on a different folder and videos can be called from that folder when ever required. Default size is 2 mb for video files but we can change that size from max_file size option in php.ini file.

What are the different types of errors in PHP?

There are three types of errors encountered in PHP.

  • Notice: These are very normal and non-critical errors and they even not displayed to users. For examples accessing a variable that not existed at all.
  • Warning: These are little bit critical errors. These results are displayed to users but do not affect the output of code. For example trying to include any file that is not exists.
  • Fatal errors: These are really critical errors. For example calling any non existence class.

What are the different errors in PHP?

In PHP, there are three types of runtime errors, they are:

Warnings:
These are important errors. Example: When we try to include () file which is not available. These errors are showed to the user by default but they will not result in ending the script.
Notices:
These errors are non-critical and trivial errors that come across while executing the script in PHP. Example: trying to gain access the variable which is not defined. These errors are not showed to the users by default even if the default behavior is changed.
Fatal errors:
These are critical errors. Example: instantiating an object of a class which does not exist or a non-existent function is called. These errors results in termination of the script immediately and default behavior of PHP is shown to them when they take place. Twelve different error types are used to represent these variations internally.

Q: What’s a PHP Session?

A: PHP Session is an object created by the PHP engine that persists data between HTTP requests

Q: What are tags used for?

A: They allow to output the result of the expression between the tags directly to the browser response.

Q: How do you define a constant?

A: define(“CONSTANT_NAME”, “constant value”);

Q: How would you get the number of parameters passed into a method?

A: use the fun_num_args() call within the method

Q: How would you create a MySQL database from PHP?

A: mysql_query(“CREATE DATABASE db_name” connector);

Q: How would you see all tables in a database?

A: mysql> use db_name; show tables;

Q: How do you change a password for a given user via mysqladmin utility?

A: mysqladmin -u root -p password “newpassword”

1. What is PHP ?
Ans: PHP is a server-side scripting language used to develop dynamic web applications.

2. What is Echo in PHP?
Ans: Echo is used to print a statement in PHP.

3. What is the difference between Echo and Print in PHP ?
Ans: Echo and Print almost gives same result. But Echo Returns “void” where as Print returns 0 or 1.

4. What is the difference between include and require in PHP ?
Ans: Include and Require functionally same. But Include show a warning and executes code after it if any error. Require raises a fetal error and stops further code process placed after it.

5. What is the difference between GET and POST ?
Ans: Get sends data upto 1024 bytes and limited. We cannot send sensitive data using get. Because the data will appear in browser url. Where as POST can send large amount of data and also suitable to send sensitive data (like passwords etc.)

6. What is Array in PHP ?
Ans: Array stores collection of values. You can declare array in PHP as like this.
$fruits = array(‘apple’, ‘grape’, ‘orange’);

7. What is Print in PHP ?
Ans: Print is not really a function. It is a language construct. So you can use with out parentheses with its argument list.

8. What is in_array() in PHP?
Ans: In_array is used to check if a value exists in the array or not.

9. What is count() function in PHP ?
Ans: Count is used count number of elements in the array.

10. What is difference between session and cookie ?
Ans: A session stores data in the server where cookie stores data in the client system in the form of a text file.

11. How to start session in PHP ?
Ans: To start session in PHP you should use session_start() function.

12. How to destroy a session in PHP?
Ans: To destory session you should use session_destory() function.

13. How to remove particular value from session in PHP ?
Ans: To remove a value there is unset function in PHP.
EX: unset($_SESSION[‘val’]);

14. How to create a cookie in PHP ?
Ans: Use Setcookie(“sample”, “ram”, time()+3600) method like this.

15. Explain few loops in PHP ?
Ans: There are loops like for, while, do..while, foreach etc. available in PHP.

16. What is the difference between MYSQL and MYSQLI?
Ans: MySQLI is an improved version of MYSQL. MYSQLI has object oriented interface where as MYSQL doesn’t.

17. How to establish connection to MYSQL using PHP ?
Ans: To establish connection we use MYSQL_CONNECT(HOSTNAME,USERNAME,PASSWORD) OR MYSQLI_CONNECT(HOSTNAME,USERNAME,PASSWORD,DATABASE).

18. How to Execute a Query in PHP against MYSQL ?
Ans: To execute query PHP uses MYSQL_QUERY($QUERY) OR MYSQLI_QUERY($CONNECTION,$QUERY).

19. Define Explode in PHP ?
Ans: Explode is to break a string into array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.
Syntax : array explode ( string $delimiter , string $string [, int $limit ] );

20. What is mysqli_real_escape_string() function in PHP ?
Ans: The above function is used to escapes special characters in a string for use in an SQL statement.

21. What is the difference between Split() and Explode() ?
Ans: Split function splits string into array by regular expression. Explode splits a string into array by string.

22. How to strip whitespace in a string ?
Ans: There is trim() function to remove whitespace from a string.

23. What is header() function in PHP ?
Ans: It is used to send HTTP Header to the client browser. You need to use this function before passing actual output. You cannot print any HTML element before this function.

24. How can you break PHP script ?
Ans: You can use exit() function for that.

25. What is the default page in web server ?
Ans: Most of the times it will be index page.

26. How can you fine string lenght in PHP ?
Ans: By using strlen() function.

27.What is rand() function in PHP ?
Ans: It is used to generate random numbers.

28. What is the meaning of isset() function in PHP ?
Ans: It is used to understand whether a value is set to a variable or not.

29. What is Associative Array in PHP ?
Ans: Associative array represents data in the form of key-value pairs.
Ex: SNO-111, NAME-RAJ etc. The given SNO, NAME are said to be keys and 111, RAJ are called values here.

29. What is action attribute in HTML Form tag ?
Ans: It is to send form-data to the server.

30. Which attribute we use when uploading files?
Ans: We use enctype = “multipart/form-data” at the time of uploading files.

31. How to create an array inside HTML input ?
Ans: You can use <input name=”NameArray[]” /> like this to maintain array inside input.

32.How to define a constant in PHP ?
Ans: To define a constant in PHP it uses “define” keyword.
Ex: define (“constant”,100)

33. How to send a mail in PHP ?
Ans: You can send a mail in PHP with mail() function or SMTP details.

34. What are arguments in Mail() in PHP ?
Ans: It contains mail($to,$subject,$message,$headers).

35. What is the difference between mysql_connect and mysql_pconnect?
Ans: mysql_pconnect establish persistent connection means eventhough the script execution is completed SQL link will not be closed. mysql_connect provides new database connection everytime.

36. What is the difference between $var and $$var ?

Ans: Both are said to be variables. $$var is a variable who’s name is stored $var.
Ex: $var = ‘message’ – it represents Message.
Ex: $$var is the same as $message

37. What is the difference between mysqli_fetch_array() and mysqli_fetch_assoc() functions ?
Ans: mysqli_fetch_array() evaluates rows using keys and indexes where as mysqli_fetch_assoc() array evaluates data by using keys only.

38. How to get current session Id in PHP ?
Ans: You can get current session id using session_id() function.

39.How to delete a file from the system?
Ans: Unlink() function is used to delete a file in file system.

40. What is SQL Injection ?
Ans: SQL injection is pass vulnerabilities into your web application. It is a malicious code injection technique.

41. How to we stop SQL Injection in PHP?
Ans: You can prevent them by using mysqli_real_escape_string() or htmlentities() functions etc.

42. What is htmlentities ?
Ans: It converts entire application characters to HTML characters.

43. Describe types of errors in php ?
Ans:
Fetal Errors :
Fetal errors are critical errors. The result will cause termination of script.

Warnings :
These are important errors. The notice user to rectify the code but do not result the code.

Notices :
These errors are non-critical and trivial errors that come across while executing the script in PHP.

44. How to can we encrypt data in PHP ?
Ans: MD5 PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg);

mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] );
Encrypts plaintext with given parameters.

45. What are superglobal variables in PHP?
Ans: There are $_GET,$_POST,$_SESSION,$_COOKIE,$_REQUEST etc. are called superglobal variables in PHP.

46. Can we use a number in the begining of a variable declaration ?
Ans: No. You cannot use a number in the begining of variable declaration. You cannot use even special characters except _ (underscore).

47. How to find the position of the first occurrence of a substring in a string ?
Ans: strpos() is used to find the position of the first occurrence of a substring in a string.

48. What is php.ini file?
Ans: It is simply a configuration file in PHP. It affects PHP functionality. You can use phpinfo() to check php.ini path.

49. Is PHP a case sensitive language ?
Ans: Yes it is.

50. What are the data types of PHP ?
Ans: Integers, Doubles, Booleans, NULL, Strings, Arrays, Objects, and Resources.

51. What is NULL ?
Ans: NULL is a special type which contains only one value : NULL. If you want any variable to set NULL just assign it.

52.What is the use of Constant Function ?
Ans: It is used to return constant value.
Ex:
<?php
define(“val”, 500);
echo val;
echo constant(“val”); // same thing as the previous line
?>

53.What are MAGIC Constants in PHP ?
Ans: PHP provides a large number of predefined constants to any script which it runs known as magic constants.

54. What is the use of _LINE_ constant in PHP ?
Ans: It is to represent current line number of the file.

55. What is _FILE_ Constant?
Ans: It is to represent full path of the file.

56. What is _FUNCTION_ constant ?
Ans: It is to represent function name.

57. What is _CLASS_ constant ?
Ans: It represents class name.

58. What is _METHOD_ constant ?
Ans: It is to represent method name.

59. What is Break statement in PHP ?
Ans: It is to terminate code especially in for loop and switch etc.

60. What is multidimensional Array ?
Ans: An array containing one or more arrays and values are accessed using multiple indices.

61. How to can you concatenate two strings ?
Ans: By using a simple period sign (.) .

62. How to find environment variables in PHP ?
Ans: You can use getenv() function for this.

63. What is $_PHP_SELF in PHP ?
Ans: It is process the action same form.

64. How to sort an array in PHP ?
Ans: For this, there is sort() function in PHP ?

65. How to read a file in PHP ?
Ans: You can open a file using fopen() after that you can fread() function to read a file.

66.How to delete a cookie in PHP ?
Ans: To delete a cookie you should call setcookie() with the name argument only.

67. What is the use of $_FILE array in PHP ?
Ans: It is used represent file information of an uploading file.

68. How will you access the uploaded file in PHP ?
Ans: Using $_FILES[‘file’][‘tmp_name’] − it provides access to the uploaded file in the temporary directory on the web server.

69. How to know updaloaded file name ?
Ans: using $_FILES[‘file’][‘name’] statement.

70. How to know uploaded file size ?
Ans: Using $_FILES[‘file’][‘size’] statement.

71. How to know error while uploading a file ?
Ans: Using $_FILES[‘file’][‘error’] statement.

Top Magento Interview Questions Answers

1. What is Magento and how it is different from other e-commerce solutions available in the market?
2. How to create new Magento extensions?
3. How to override Magento functions?
4. How you can change the layout of a site?
5. What is store concept in Magento? Can we launch multiple stores from same domain?
6. How we can increased the speed of a Magento application?
7. What is Magento cache? How we can control it?
8. Can we setup out own cache engine? How?
9. How to change the Magento admin password if you forgot it?
10. What steps you will take to upload a Magento site to a different domain?
11. Examples of some popular extensions? How they can be installed in Magento?
12. What are hardware requirements for Magento?
13. How you can create multiple thumbnails of product or item images?
14. Can you integrate a new payment gateway to Magento? How?
15. Can you change the flow of checkout? How?

  • How to execute an sql query? How to fetch its result ?
  • Write a program using while loop
  • How we can retrieve the data in the result set of MySQL using PHP?
  • What is the use of explode() function ?
  • What is the difference between explode() and split() functions?
  • What is the use of mysql_real_escape_string() function?
  • Write down the code for save an uploaded file in php.
  • How to create a text file in php?
  • What is the use of header() function in php ?
  • How stop the execution of a php scrip ?
  • what is the use of rand() in php?
  • What is mean by an associative array?
  • What is the importance of “method” attribute in a html form?
  • What is the importance of “action” attribute in a html form?
  • What is the use of “enctype” attribute in a html form?
  • Define Object-Oriented Methodology
  • How do you define a constant?
  • How send email using php?
  • How to find current date and time?
  • Difference between mysql_connect and mysql_pconnect?
  • What is the use of “ksort” in php?
  • What is the difference between $var and $$var?
  • What are the encryption techniques in PHP
  • What is the use of the function htmlentities?
  • How to delete a file from the system
  • How to get the value of current session id?
  • What are the different types of errors in PHP ?
  • what is sql injection ?
  • What is x+ mode in fopen() used for?
  • What is PEAR?
  • Distinguish between urlencode and urldecode?
  • What are the different errors in PHP?
  • What are the different validators in ASP.NET?
  • How to execute an sql query? How to fetch its result ?
  • What is the difference between Session and Cookie?
  • What are different types of Runtime Errors in PHP?
  • Explain the “unlink” and “unset” functions.
  • How can we encrypt the password using PHP?
  • What does PEAR stands for?
  • How can PHP and Javascript interact?
  • What is the difference between mysql_fetch_object() and mysql_fetch_array()?
  • How is the ternary conditional operator used in PHP?
  • what is the difference between for and foreach?
  • What is the difference between the functions strstr() and stristr()?
  • What are the two main string operators?
  • What does $_SERVER means?
  • What is faster?
  • How is it possible to cast types in PHP?
  • What is the most convenient hashing method to be used to hash passwords?
  • what is the static variable in function useful for?

What is the difference between PHP4 and PHP5?

PHP4 cannot support oops concepts and Zend engine 1 is used.

PHP5 supports oops concepts and Zend engine 2 is used.

Error supporting is increased in PHP5.

XML and SQLLite will is increased in PHP5.

 Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?

Yes we can include that many times we want, but here are some things to make sure of:

(including abc.PHP, the file names are case-sensitive)

there shouldn’t be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

What is meant by nl2br()?

Anwser1:

nl2br() inserts a HTML tag <br> before all new line characters n in a string.

echo nl2br(“god bless n you”);

output:

god bless<br>

you

In how many ways we can retrieve data in the result set of MYSQL using PHP?

mysql_fetch_array – Fetch a result row as an associative array, a numeric array, or both

mysql_fetch_assoc – Fetch a result row as an associative array

mysql_fetch_object – Fetch a result row as an object

mysql_fetch_row —- Get a result row as an enumerated array

What are the functions for IMAP?

imap_body – Read the message body

imap_check – Check current mailbox

imap_delete – Mark a message for deletion from current mailbox

imap_mail – Send an email message

What are encryption functions in PHP?

CRYPT()

MD5()

What is the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used)

htmlentities() – Convert ALL special characters to HTML entities

What is the functionality of the function htmlentities?

htmlentities() – Convert all applicable characters to HTML entities

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

How can we get the properties (size, type, width, height) of an image using php image functions?

To know the image size use getimagesize() function

To know the image width use imagesx() function

To know the image height use imagesy() function

Top asked php interview questions 2016- 2017

  • php interview questions and answers for experienced
  • php interview questions and answers for freshers
  • php interview questions and answers pdf
  • php tutorial
  • mysql interview questions
  • php interview questions and answers for freshers pdf
  • php interview questions pdf
  • php interview questions for freshers
  • php interview questions for freshers pdf free download
  • php interview questions and answers for 3 year experience pdf
  • php interview questions and answers for 1 year experience pdf free download
  • php interview questions and answers for freshers pdf file
  • php interview questions and answers for freshers in pdf format
  • php interview questions for freshers online
  • mysql interview questions and answers for freshers pdf
  • c interview questions and answers for freshers pdf
Courses: , , , ,