• PHP Video Tutorials

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 instances of programmer-defined classes?

A - Strings

B - Arrays

C - Objects

D - Resources

Answer : C

Explanation

Objects: are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.

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 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 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 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 8 - 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 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 can be used to create a MySql database using PHP?

A - mysql_connect()

B - mysql_query()

C - mysql_close()

D - None of the above

Answer : B

Explanation

PHP uses mysql_query function to create a MySQL database.

php_questions_answers.htm
Advertisements