1. What is the purpose of continue statement?

continue causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

2. What is the purpose of _CLASS_ constant?

_CLASS_ − The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.

3. What is the purpose of _METHOD_ constant?

_METHOD_ − The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).

4. Can you assign the default values to a function parameters?

Yes! You can set a parameter to have a default value if the function's caller doesn't pass it.

5. What is associate array in PHP?

Associative array − An array with strings as index. This stores element values in association with key values rather than in a strict linear index order.

6. What are PHP magic constants?

PHP provides a large number of predefined constants to any script which it runs known as magic constants.

8. What do you mean by having PHP as whitespace insensitive?

Whitespace is the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage returns (end-of-line characters). PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row.one whitespace character is the same as many such characters.

9. What is the purpse $_REQUEST variable?

The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. We will discuss $_COOKIE variable when we will explain about cookies. The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

10. What is the purpose of _LINE_ constant?

_LINE_ − The current line number of the file.

11. What is the purpose of $_FILES variable in PHP?

This is a global PHP variable. This variable is an associate double dimension array and keeps all the information related to uploaded file.

12. What is the purpose of php.ini file?

The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality. The php.ini file is read each time PHP is initialized.in other words, whenever httpd is restarted for the module version or with each script execution for the CGI version. If your change isn.t showing up, remember to stop and restart httpd. If it still isn.t showing up, use phpinfo() to check the path to php.ini.

13. How will you delete a cookie in PHP?

To delete a cookie you should call setcookie() with the name argument only.

14. How will you open a file in readonly mode?

The PHP fopen() function is used to open a file. It requires two arguments stating first the file name and then mode in which to operate. "r" mode opens the file for reading only and places the file pointer at the beginning of the file.

15. How will you start a session in PHP?

A PHP session is easily started by making a call to the session_start() function.This function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start() at the beginning of the page.

16. How will you check if a file exists or not using php?

File's existence can be confirmed using file_exist() function which takes file name as an argument.

17. How will you generate random numbers using PHP?

The PHP rand() function is used to generate a random number. This function can generate numbers with-in a given range. The random number generator should be seeded to prevent a regular pattern of numbers being generated. This is achieved using the srand() function that specifies the seed number as its argument.

18. How will you get information sent via post method in PHP?

The PHP provides $_POST associative array to access all the sent information using POST method.

19. How will you unset a single session variable?

Here is the example to unset a single variable −

<?php
unset($_SESSION['counter']);
?>

20. How will you get cookies using PHP?

PHP provides many ways to access cookies. Simplest way is to use either $_COOKIE or $HTTP_COOKIE_VARS variables.

21. How will you get information sent via get method in PHP?

The PHP provides $_GET associative array to access all the sent information using GET method.

22. What are the common usage of PHP?

Common uses of PHP −
☛ PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
☛ PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data, return data to the user.
☛ You add, delete, modify elements within your database thru PHP.
☛ Access cookies variables and set cookies.
☛ Using PHP, you can restrict users to access some pages of your website.
☛ It can encrypt data.

23. How can you sort an array?

sort() − Sorts an array.

24. How will you set cookies using PHP?

PHP provided setcookie() function to set a cookie. This function requires upto six arguments and should be called before <html> tag. For each cookie this function has to be called separately.

setcookie(name, value, expire, path, domain, security);

25. How will you destroy the session?

A PHP session can be destroyed by session_destroy() function.

26. How will you include the content of a PHP file into another PHP file?

There are two PHP functions which can be used to included one PHP file into another PHP file.

☛ The include() Function

☛ The require() Function

27. How will you get environment variables in PHP?

PHP provides a function getenv() to access the value of all the environment variables.

28. Explain the importance of the function htmlentities?

The htmlentities() function converts characters to HTML entities.

29. Explain the syntax for 'foreach' loop in PHP?

The foreach statement is used to loop through arrays. For each pass the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass next element will be processed.

foreach (array as value)
{
code to be executed;
}

30. Why would you use === instead of ==?

If you would want to check for a certain type, like an integer or boolean, the === will do that exactly like one would expect from a strongly typed language, while == would convert the data temporarily and try to match both operand's types. The identity operator (===) also performs better as a result of not having to deal with type conversion. Especially when checking variables for true/false you want to avoid using == as this would also take into account 0/1 or other similar representation.

31. How will you access the actual name of the uploaded file in PHP?

Using $_FILES['file']['name'] − it provides the actual name of the uploaded file.

32. How will you make a check that a cookie is set or not?

You can use isset() function to check if a cookie is set or not.

33. How will you concatenate two strings in PHP?

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

<?php
$string1="Global Guideline";
$string2="Interviews";
echo $string1 . " " . $string2;
?>

This will produce following result:
Global Guideline Interviews

34. Tell me In how many ways you can embed PHP code in an HTML page?

All PHP code must be included inside one of the three special markup tags ate are recognized by the PHP Parser.

<?php PHP code goes here ?>
<? PHP code goes here ?>
<script language="php"> PHP code goes here </script>
Most common tag is the <?php...?>

35. How will you access the size of the uploaded file in PHP?

Using $_FILES['file']['size'] − it provides the size in bytes of the uploaded file.