Learn PHP MCQs

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

Which of the following is used to set the output buffering in PHP?

1) ob_start()

2) buffer_output()

3) output_buffering()

4) start_output_buffering()

Answer : Option 1

How do you redirect to another page in PHP?

1) header("Location: url");

2) redirect("url");

3) goto("url");

4) None of the above

Answer : Option 1

What is the output of `echo 10 % 3;` in PHP?

1) 1

2) 3

3) 0

4) 10

Answer : Option 1

How do you compare two strings in PHP?

1) strcmp()

2) str_compare()

3) compare()

4) strdiff()

Answer : Option 1

Which function is used to compress a string in PHP?

1) gzcompress()

2) compress()

3) strcompress()

4) zip()

Answer : Option 1

How do you create a constant in PHP?

1) define()

2) const()

3) constant()

4) set_constant()

Answer : Option 1

What does the `array_search()` function do in PHP?

1) Searches for a value in an array and returns its key

2) Searches for a key in an array and returns its value

3) Searches for an element in an array and returns its index

4) Searches for a value in an array and returns true if found

Answer : Option 1

Which function is used to read an entire file into a string in PHP?

1) file_get_contents()

2) read_file()

3) fread()

4) file_read()

Answer : Option 1

What does the `isset()` function do in PHP?

1) Checks if a variable is set and is not NULL

2) Checks if a variable is initialized

3) Checks if a variable is of a certain type

4) Checks if a variable is empty

Answer : Option 1

Which of the following is a valid way to define a PHP function?

1) function myFunction() { }

2) def myFunction() { }

3) create myFunction() { }

4) define myFunction() { }

Answer : Option 1