Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

PHP Interview Questions

1. What is the closing tag used by a PHP-driven web page?

A. />
B. #>
C. ?>
D. .>

2. Which PHP conditional operator means the values are equal AND of the same data type?

A. ==
B. ||
C. ===
D. ==?

3. Which of the following statements is true regarding variables in PHP (choose two)?

A. Variable names in PHP are case sensitive.
B. Variable names in PHP are not case sensitive.
C. PHP variables need to be declared before they can be used.
D. PHP variables do not need to be declared before they can be used.

4. You are evaluating a script written by a previous employee. That script contains a require statement that causes the script to exit when an error occurs. You want to change this so the script will generate a warning when such an error occurs, but keep on running. What should you replace require with?

A. involve
B. need
C. include
D. call_for

5. Which of the following does not represent a comment in a PHP script?

A. // This is a comment
B. ?>?>?>?>?>?>?>?>
C. # This is a comment
D. /* This is a comment */

6. Which escape character in PHP renders a linefeed?

A. \n
B. \r
C. \t
D. \\

7. What file is used to configure global PHP settings? ______________ (Fill in the blank.)

8. If the value of $AU is currently 7, what is its value as a result of the command $AU++;

A. 8
B. 9
C. 14
D. 49

9. Which printf type specifier is used for a floating point value?

A. d
B. f
C. s
D. u

10. Which PHP logical operator is used to see if both a and b are true?

A. a & b
B. a && b
C. a | b
D. a || b

11. If an array holds 100 entries, which identifier signifies the first entry?

A. 100
B. 99
C. 1
D. 0

12. What function must be called to send the random number generator before array_rand()?

A. limit()
B. scope()
C. srand()
D. hinum()

13. Which two choices below represent the default order resulting from a sort utilizing asort()?

A. A-Z
B. Z-A
C. 0-9
D. 9-0

14. Which of the following is not true for variable names?

A. They can contain an underscore character
B. They can begin with a numeric character
C. They can begin with an alpha character
D. They can contain alphanumeric characters

15. What is the opening tag used on a PHP-driven web page?

A. ?>?>?>?>?>?>?>?>
D.

Answers

1. The closing tag used by PHP is ?>. Answer: C.

2. The PHP conditional operator of three equal signs (===) means the values are equal and of the same data type. Answer: C.

3. PHP variable names are case sensitive and variables do not need to be declared before they can be used. Answer: A and D.

4. The include instruction will create a warning, but allow the script to continue running when an error is encountered. Answer: C.

5. There are at least three ways to create comments in a PHP script, and
6. The \n escape character in PHP renders a linefeed. Answer: A.

7. The global configuration file is php.ini.

8. The command $AU++; increments the variable by one – changing it from 7 to 8. Answer: A.

9. The printf type specifier f is used for a floating point value. Answer: B.

10. The PHP logical operator to use to see if both a and b are true would be a && b. Answer: B.

11. The first entry is 0, the second is 1, and the numbers increment from there. Answer: D.

12. The srand() function must be called to send the random number generator before array_rand(). Answer: C.

13. The default order resulting from a sort utilizing asort() is alphabetic (A-Z) and lowest to highest (0-9). Answer: A and C.

14. Variable names cannot begin with a numeric character. Answer: B.

15. The opening tag used by PHP is ?>?>?>?>?>?>?>?>
16. Curly braces are used to separate blocks of statements within a control structure. Answer: C.

17. The settype function can be used to assign a data type to a variable. Answer: C.

18. The REMOTE_ADDR HTTP variable contains the IP address of the machine making a request. Answer: D.

19. The POST method should be used for a form as described. Answer: A.

20. If the result is not a whole number, it is assigned the double data type If it is a whole number, integer is assigned. Answer: B.

21. The r+ mode of the fopen() function opens a file for reading or writing, maintains exiting content, and places the file pointer at the beginning of the file. Answer: C.

22. The copy() function can be used to copy a file. Answer: A.

23. To set a cookie to expire 24 hours from now, compute the number of seconds and use the time() function: $cookie_expire = time() +86400. Answer: C.

24. The semicolon character (;) is used as a statement terminator to indicate the end of a PHP command. Answer: D.

25. The command $days = array(); will initialize the $days array. Answer: B.

26. The file_exists() function can be used to see if a file by the given name is already in existence. Answer: D.

27. The value of $_COOKIE[user] is equal to what was set in the cookie. Answer: C.

28. The array_merge() function should be used to combine two or more existing arrays. Answer: B.

29. The function to use is session_start()

30. After opening a file with the fopen() function, fclose() is used to close the file pointer. Answer: A.

31. The gettype function can be used to show the data type for a variable. Answer: B.

32. The rmdir() function removes a directory from a file system. Answer: A.

33. sleep() accepts seconds and usleep() accepts milliseconds. Answer: B.

34. The sizeof() function can tell how many elements are in an array Answer: D.

35. Information about a session, by default, is configured in the PHP configuration file to be saved beneath /tmp. Answer: C.

36. $_ENV contains variables provided to a script by means of the server environment. Answer: D.

37. The unlink() function can be used to delete a file. Answer: C.

38. The unset function can be used to destroy a variable. Answer: D.

39. The "a" mode of the fopen() function opens a file for writing and places the file pointer at the end of the file. Answer: B.

40. The HTTP_USER_AGENT HTTP variable contains the browser type, and browser version, among other values. Answer: D.

41. This operation subtracts 150 from the existing value. Answer: C.

42. Parentheses are used to enclose conditional expressions. Answer: B.

43. The Boolean PHP data type can be either TRUE or FALSE. Answer: C.

44. $_FILES contains variables provided to a script by means of file uploads. Answer: A.

45. The RAND_MAX constant identifies the highest random number that a system can generate. Answer: D.

46. PHP provides support for POSIX through functions of the ereg class. Answer: B.

47. From a Boolean standpoint, every zero value in PHP is considered false. Answer: B.

48. The arsort() function places results in the opposite order of asort(). Answer: A.

49. The printf type specifier s is used for a string. Answer: C.

50. The != PHP conditional operator means not equal to. Answer: A.



This post first appeared on Tech Interview Questions & Tips, please read the originial post: here

Share the post

PHP Interview Questions

×

Subscribe to Tech Interview Questions & Tips

Get updates delivered right to your inbox!

Thank you for your subscription

×