Learn PHP MCQs

Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.

Which function is used to get the current timestamp in PHP?

1) time()

2) timestamp()

3) date()

4) current_time()

Answer : Option 1

How do you check if a variable is set in PHP?

1) isset($var);

2) var_set($var);

3) is_set($var);

4) check_set($var);

Answer : Option 1

Which of the following function is used to convert a string to an array?

1) explode()

2) implode()

3) split()

4) array_split()

Answer : Option 1

What is the correct way to declare an abstract class in PHP?

1) abstract class ClassName {}

2) class abstract ClassName {}

3) abstract ClassName() {}

4) abstract {}

Answer : Option 1

Which function is used to get the keys of an array in PHP?

1) array_values()

2) array_keys()

3) array_keys_values()

4) array_data()

Answer : Option 2

Which of the following is a magic method in PHP?

1) __construct()

2) constructor()

3) __start()

4) magic()

Answer : Option 1

How do you define a multi-dimensional array in PHP?

1) $array = array(array(), array());

2) $array = [[], []];

3) $array = array([[], []]);

4) All of the above

Answer : Option 4

How do you get the type of a variable in PHP?

1) gettype($var);

2) typeof($var);

3) vartype($var);

4) var_type($var);

Answer : Option 1

Which of the following is not a valid PHP loop?

1) for

2) foreach

3) loop

4) while

Answer : Option 3

Which of the following is used to handle errors in PHP?

1) try-catch

2) if-else

3) switch-case

4) errorHandler()

Answer : Option 1