Learn PHP MCQs

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

What is the output of `echo round(2.675, 2);` in PHP?

1) 2.68

2) 2.67

3) 2.7

4) 2.6

Answer : Option 1

Which function is used to include and evaluate a specified file in PHP?

1) include()

2) require()

3) include_once()

4) All of the above

Answer : Option 4

How do you get the number of rows in a MySQL result set in PHP?

1) mysqli_num_rows()

2) row_count()

3) num_rows()

4) get_rows()

Answer : Option 1

What is the purpose of the `header()` function in PHP?

1) Sends a raw HTTP header to the client

2) Sets the content type of the page

3) Redirects to another page

4) Both a and c

Answer : Option 4

How do you ensure that a file upload is successful in PHP?

1) Check for `$_FILES` and `$_FILES["file"]["error"]`

2) Verify the file size

3) Check the file type

4) All of the above

Answer : Option 1

Which function is used to search for a substring within a string in PHP?

1) strpos()

2) search()

3) str_search()

4) find()

Answer : Option 1

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

1) Checks if a variable is a number or numeric string

2) Checks if a variable is an integer

3) Checks if a variable is a floating-point number

4) None of the above

Answer : Option 1

How do you replace all occurrences of a substring in a string in PHP?

1) str_replace()

2) replace_all()

3) str_substitute()

4) replace()

Answer : Option 1

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

1) count()

2) array_length()

3) length()

4) size()

Answer : Option 1

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

1) Parses a URL and returns its components

2) Parses a URL and returns the full URL

3) Parses a URL and extracts parameters

4) None of the above

Answer : Option 1