PHP Interview Questions and answer for fresher

Hi friends, i m also a developer of PHP and i know what the problem faced during first interview when we all was fresher. in this post i m explaining which type of questions interviewer can ask in interview. PHP is a important post of web and every web developer should have the basic PHP knowledge. i hope you learn very easy to understand. in this post  i m explain frequently asked question for fresher.

1. what is PHP?

- PHP stands for Hypertext Preprocessor and php is a server side scripting language and commonly used for web applications.

-PHP has many frameworks and cms for creating any websites, non technical person can also create simple site using CMS.

-wordpress, oscommerce are the famus CMS of the php. and it is very easy to learn.

2. How to include php file?

- we can include file using either include() or require function with file path.

3. whats the difference between require(), include()?

- if we use require() function with file path and if that file not found on that path than it will give a fatal error. it stop the execution after getting error.

-and if we use include() function with file path and if that file not found on that path than it will give a warning but it not stop the execution.

4. What are the difference between GET and POST methods?

- in get method data is passing in url and getting from url while post methods data not passing in url.

-using get method we can send data only 1024 bytes while using post we can send large amount of data and post method is secured.

5. How to declare array using PHP?

- var $my_arr= array(‘smitcky’,'smitcky2′,’smitcky3′);

6. whats the use of in_array functions in php?

- in_array() functions used for checking whether value is exist or not in particular array.

-in_array is used only with array.

-in short you have one array and you have to checked any value something like “smitcky” and have to checked whether smitcky word is exist in any array or not.

7. How to count any elements array or object?

- using count() function we can do that.

8.what is the difference between session and cookie?

- Click here for view answer in full detail

9.How to set Cookie and how to Get cookie using php?

- using setcookie function we can set cookie. e.g Setcookie(“smitcky”, “test”, time()+3600);

-for get cookie e.g <?php echo $_COOKIE['smitcky'];?>

10. How to create, set and remove session using php?

- using session_start() session is creating.

- for set value in session we have to use $_SESSION['smitcky']=’yes’; 

-and if we want to removed session that one we have created than using unset() function we can remove created session  for e.g i want to remove smitcky session than i have use like unset($_SESSION['smitcky']);

 11. How many loops we can use in php?

- while, do while, for and foreach (You should learn for each loops usage);

12. For Array which loops you can use?

- foreach only.

13. write a simple program using while loop in php?

 14. How we can retrieve data result set og mysql with php?

- mysql_fetch_array




15. whats the use of extract() in php?

- exract() functions is converting all the data post array as a variable name. i.e suppose you have created one form and in that form you have used input type username and password and taken one button and on click on that button you are posting that form and there if you use extract($_POST) than your username’s input name and password’s input name converted as a variable like $username and $password.

- sometimes you using $_POST['username'], so instead of if you use extract($_POST) than you will directly get that as a variable i.e $username;

16.  what the use of implode and explode in php?

- implode is used for joining two or more variable while explode used for removed joined array with its seperator.

17. How to redirect page using php?

- using header(“Location: mypage.php”);

18. How to stop execution anywhere?

- using exit() function you can do that

19. Which function is used for generate random number?

-using rand() function.

20. whats the use of isset?

-it determine whether that variable is set and it not null.

21. whats the use of action attribute in form?

- it determine where that form will submit.

22. How to define constant in php?

- using define function i.e define(“MY”,150);

23. For Sending mail which function is used in php?

- using mail() function.

24. How to print current date using php?

- using date function i.e date(“d-m-Y”);

25.whats the use of ksort in php?

- this function is used for sort an array as a reverse order.

26. How to delete a file using php?

- using unlink() function.

27. what are the array type in php?

- notice,warning and fatal errors.