• 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 II

Answer : C

Explanation

Both of the above options are correct.

Q 3 - Which of the following magic constant of PHP returns current line number of the file?

A - _LINE_

B - _FILE_

C - _FUNCTION_

D - _CLASS_

Answer : A

Explanation

_LINE_ − The current line number of the file.

Q 4 - Which of the following magic constant of PHP returns full path and filename of the file?

A - _LINE_

B - _FILE_

C - _FUNCTION_

D - _CLASS_

Answer : B

Explanation

_FILE_ − The full path and filename of the file. If used inside an include,the name of the included file is returned. Since PHP 4.0.2, _FILE_ always contains an absolute path whereas in older versions it contained relative path under some circumstances.

Q 5 - Which of the following magic constant of PHP returns function name?

A - _LINE_

B - _FILE_

C - _FUNCTION_

D - _CLASS_

Answer : C

Explanation

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

Q 6 - Which of the following magic constant of PHP returns class name?

A - _LINE_

B - _FILE_

C - _FUNCTION_

D - _CLASS_

Answer : D

Explanation

_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.

Q 7 - Which of the following magic constant of PHP returns class method name?

A - _METHOD_

B - _FILE_

C - _FUNCTION_

D - _CLASS_

Answer : A

Explanation

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

Q 8 - Which of the following keyword terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch?

A - break

B - continue

Answer : A

Explanation

break terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.

Q 9 - Which of the following keyword causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating?

A - break

B - continue

Answer : B

Explanation

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

Q 10 - Which of the following array represents an array with a numeric index?

A - Numeric Array

B - Associative Array

C - Multidimentional Array

D - None of the above.

Answer : A

Explanation

Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.

Q 11 - Which of the following array represents an array with strings as index?

A - Numeric Array

B - Associative Array

C - Multidimentional Array

D - None of the above.

Answer : B

Explanation

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.

Q 12 - Which of the following array represents an array containing one or more arrays?

A - Numeric Array

B - Associative Array

C - Multidimentional Array

D - None of the above.

Answer : C

Explanation

Multidimensional array − An array containing one or more arrays and values are accessed using multiple indices.

Q 13 - Which of the following operator is used to concatenate two strings?

A - .

B - +

C - append

D - None of the above.

Answer : A

Explanation

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

Q 14 - Which of the following function is used to get length of a string?

A - size()

B - strlen()

C - length

D - None of the above.

Answer : B

Explanation

The strlen() function is used to find the length of a string.

Q 15 - Which of the following function is used to locate a string within a string?

A - search()

B - locate()

C - strpos()

D - None of the above.

Answer : C

Explanation

The strpos() function is used to search for a string or character within a string.

Q 16 - Which of the following function is used to get environment variables in PHP?

A - search()

B - environment()

C - env()

D - getenv()

Answer : D

Explanation

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

Q 17 - Which of the following variable is used to get user's browser and operating system details in PHP?

A - HTTP_USER_AGENT

B - USER

C - AGENT

D - None of the above.

Answer : A

Explanation

One of the environemnt variables set by PHP is HTTP_USER_AGENT which identifies the user's browser and operating system.

Q 18 - Which of the following variable is used to generate random numbers using PHP?

A - srand()

B - rand()

C - random()

D - None of the above.

Answer : B

Explanation

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 specifiies the seed number as its argument.

Q 19 - Which of the following variable is used for the PHP script name?

A - $_PHP_SELF

B - $SELF

C - $PHP

D - None of the above.

Answer : A

Explanation

The PHP default variable $_PHP_SELF is used for the PHP script name and when you click "submit" button then same PHP script will be called.

Q 20 - Which of the following function sorts an array in reverse order?

A - rsort()

B - sort()

C - shuffle()

D - reset()

Answer : A

Explanation

rsort() − Sorts an array in reverse order.

Q 21 - Which of the following function is used to redirect a page?

A - redirect()

B - header()

C - reflect()

D - None of the above.

Answer : B

Explanation

The PHP header() function supplies raw HTTP headers to the browser and can be used to redirect it to another location. The redirection script should be at the very top of the page to prevent any other part of the page from loading.

Q 22 - Which of the following is used to get information sent via get method in PHP?

A - $_GET

B - $GET

C - $GETREQUEST

D - None of the above.

Answer : A

Explanation

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

Q 23 - Which of the following can be used to get information sent via get/post method in PHP?

A - $_REQUEST

B - $REQUEST

C - $REQUEST_PAGE

D - None of the above.

Answer : A

Explanation

The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

Q 24 - Which of the following function creates an array?

A - array()

B - array_change_key_case()

C - array_chunk()

D - array_count_values()

Answer : A

Explanation

array() − Creates an array.

Q 25 - Which of the following function can be used to get an array in the reverse order?

A - array_reverse()

B - array_search()

C - array_shift()

D - array_slice()

Answer : A

Explanation

array_reverse() − Returns an array in the reverse order.

Answer Sheet

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