PHP interview questions
Q:-11. What are the differences between require and include function?
Both include and require function are used for including file into a web page.
The main difference is, require function will produce fatal error and stop execution of script, as the name suggests this file is required for execution of this script. While include function will only produce Warning and continue the script. If file is not found.
Q:-12. What are the differences between include and include_once?
The include and include_once function are used, when you want to include a file within the script or web page. It takes one argument as string.
Include_once function is same as include function except it will execute or include that file once. You can include same file many times in case of include while in case of include_once you can only once.
You can put your include function within the loop but in case of include_once it will display only once.
Q:-13.How we get IP address of client, previous reference page etc.
By using $_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_REFERER'] etc.
Q:-14. How many ways can we get the value of current session id?
There are only one way to get value of current session id that is, session_id() function returns the current session id.
Q:-15. How can we set and destroy the cookie in PHP?
We use setcookies() function to set and destroy the cookies by using this function we can set and destroy the PHP cookies.
For set cookies setcookie("user", "", time()+300);
For destroy cookies setcookie("user", "", time()-300);
Q:-16. What are the different functions in sorting an array?
There are lot of function available for sorting an array like Sort(), arsort(), asort(), ksort(), natsort(), natcasesort(), rsort(), usort(), array_multisort().
Q:-17.What is the difference between $i-- and --$i?
The $i-- is post decrement but --$i is pre decrement.
Q:-18.How many types of arrays in PHP?
There are three types of array in PHP
Q:-19. What is the use of header function in PHP?
Header function allows sending a raw HTTP header to the client browser. The most common usages is simply redirecting a user to elsewhere i.e. to another URL.
Q:-20.What is the use of isset function?
Isset() function determine whether a variable has been declared and loaded with a value by programmer. Return true if such a variable is passed to it. If not, return false.