• PHP Video Tutorials

PHP Mock Test



This section presents you various set of Mock Tests related to PHP. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

PHP Mock Test III

Q 1 - Which of the following function returns selected parts of an array?

A - array_reverse()

B - array_search()

C - array_shift()

D - array_slice()

Answer : D

Explanation

array_slice() − Returns selected parts of an array.

Q 2 - Which of the following function returns the sum of the values in an array?

A - array_sum()

B - array_splice()

C - array_udiff()

D - array_udiff_assoc()

Answer : A

Explanation

array_sum() − Returns the sum of the values in an array.

Q 3 - Which of the following function checks if a specified value exists in an array?

A - extract()

B - in_array()

C - key()

D - krsort()

Answer : B

Explanation

in_array() − Checks if a specified value exists in an array.

Q 4 - Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

A - true

B - false

Answer : A

Explanation

Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

Q 5 - Doubly quoted strings are treated almost literally, whereas singly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

A - true

B - false

Answer : B

Explanation

Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

Answer : A

Explanation

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

Q 7 - If there is any problem in loading a file then the require() function generates a warning but the script will continue execution.

A - true

B - false

Answer : B

Explanation

If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script.

Q 8 - If there is any problem in loading a file then the include() function generates a warning but the script will continue execution.

A - true

B - false

Answer : A

Explanation

If there is any problem in loading a file then the include() function generates a warning but the script will continue execution.

Q 9 - Which of the following function opens a file?

A - fopen()

B - fread()

C - filesize()

D - file_exist()

Answer : A

Explanation

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.

Q 10 - Which of the following function is used to read the content of a file?

A - fopen()

B - fread()

C - filesize()

D - file_exist()

Answer : B

Explanation

Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.

Q 11 - Which of the following function is used to get the size of a file?

A - fopen()

B - fread()

C - filesize()

D - file_exist()

Answer : C

Explanation

The files's length can be found using the filesize() function which takes the file name as its argument and returns the size of the file expressed in bytes.

Q 12 - Which of the following function is used to check if a file exists or not?

A - fopen()

B - fread()

C - filesize()

D - file_exist()

Answer : D

Explanation

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

Q 13 - Can you assign the default values to a function parameters?

A - true

B - false

Answer : A

Explanation

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

Answer : A

Explanation

PHP provided setcookie() function to set a cookie.

Q 15 - Which of the following is used to get cookies?

A - getcookie() function

B - $_COOKIE variable

C - isset() function

D - None of the above.

Answer : B

Explanation

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

Q 16 - Which of the following is used to check that a cookie is set or not?

A - getcookie() function

B - $_COOKIE variable

C - isset() function

D - None of the above.

Answer : C

Explanation

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

Q 17 - Which of the following is used to delete a cookie?

A - setcookie() function

B - $_COOKIE variable

C - isset() function

D - None of the above.

Answer : A

Explanation

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

Q 18 - Which of the following is used to create a session?

A - session_start() function

B - $_SESSION[]

C - isset() function

D - session_destroy() function

Answer : A

Explanation

A PHP session is easily started by making a call to the session_start() function.

Q 19 - Which of the following is used to access session variables in PHP?

A - session_start() function

B - $_SESSION[]

C - isset() function

D - session_destroy() function

Answer : B

Explanation

Session variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session.

Q 20 - Which of the following is used to check if session variable is already set or not in PHP?

A - session_start() function

B - $_SESSION[]

C - isset() function

D - session_destroy() function

Answer : C

Explanation

Make use of isset() function to check if session variable is already set or not.

Q 21 - Which of the following is used to destroy the session?

A - session_start() function

B - $_SESSION[]

C - isset() function

D - session_destroy() function

Answer : D

Explanation

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

Q 22 - Which of the following provides access to the uploaded file in the temporary directory on the web server?

A - $_FILES['file']['tmp_name']

B - $_FILES['file']['name']

C - $_FILES['file']['size']

D - $_FILES['file']['type']

Answer : A

Explanation

$_FILES['file']['tmp_name'] − it provides access to the uploaded file in the temporary directory on the web server.

Q 23 - Which of the following provides the actual name of the uploaded file?

A - $_FILES['file']['tmp_name']

B - $_FILES['file']['name']

C - $_FILES['file']['size']

D - $_FILES['file']['type']

Answer : B

Explanation

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

Q 24 - Which of the following provides the size of the uploaded file in PHP?

A - $_FILES['file']['tmp_name']

B - $_FILES['file']['name']

C - $_FILES['file']['size']

D - $_FILES['file']['type']

Answer : C

Explanation

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

Q 25 - Which of the following provides content type of the uploaded file in PHP?

A - $_FILES['file']['tmp_name']

B - $_FILES['file']['name']

C - $_FILES['file']['size']

D - $_FILES['file']['type']

Answer : D

Explanation

$_FILES['file']['type'] − it provides the content type of the uploaded file in PHP.

Answer Sheet

Question Number Answer Key
1 D
2 A
3 B
4 A
5 B
6 A
7 B
8 A
9 A
10 B
11 C
12 D
13 A
14 A
15 B
16 C
17 A
18 A
19 B
20 C
21 D
22 A
23 B
24 C
25 D
php_questions_answers.htm
Advertisements