PHP Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to PHP. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 2 - Which of the following type of variables are named and indexed collections of other values?

A - Strings

B - Arrays

C - Objects

D - Resources

Answer : B

Explanation

Arrays: are named and indexed collections of other values.

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 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 5 - 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 6 - 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 7 - 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 8 - Which of the following is an associative array containing session variables available to the current script?

A - $GLOBALS

B - $_SERVER

C - $_COOKIE

D - $_SESSION

Answer : D

Explanation

$_SESSION − An associative array containing session variables available to the current script.

Q 9 - Which of the following method of Exception class returns array of the backtrace?

A - getMessage()

B - getCode()

C - getTrace()

D - getTraceAsString()

Answer : C

Explanation

getTrace() method of Exception class returns array of the backtrace.

Q 10 - Which of the following method returns a formatted string representing a date?

A - time()

B - getdate()

C - date()

D - None of the above

Answer : C

Explanation

The date() function returns a formatted string representing a date. You can exercise an enormous amount of control over the format that date() returns with a string argument that you must pass to it.

php_questions_answers.htm
Advertisements