Learn PHP MCQs

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

How do you send an email using PHP?

1) Using the `mail()` function

2) Using the `send_email()` function

3) Using the `email()` function

4) Using the `smtp_send()` function

Answer : Option 1

What is the output of `echo (10 <=> 5);` in PHP?

1) 1

2) -1

3) 0

4) Error

Answer : Option 1

Which function is used to get a substring of a string in PHP?

1) substr()

2) substring()

3) str_sub()

4) get_substr()

Answer : Option 1

How do you check if a file is writable in PHP?

1) is_writable()

2) file_writable()

3) can_write()

4) writable()

Answer : Option 1

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

1) Converts a JSON string into a PHP array or object

2) Converts a PHP array or object into a JSON string

3) Decodes a JSON file

4) Encodes a JSON string

Answer : Option 1

How do you concatenate two strings in PHP?

1) Using the `.` operator

2) Using the `+` operator

3) Using the `concat()` function

4) Using the `append()` function

Answer : Option 1

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

1) Merges one or more arrays into one

2) Splits an array into multiple arrays

3) Filters an array based on a callback

4) None of the above

Answer : Option 1

How do you convert a variable to a string in PHP?

1) Using the `strval()` function

2) Using the `to_string()` function

3) Using the `convert_to_string()` function

4) Using the `string()` function

Answer : Option 1

Which function is used to get the current date and time in PHP?

1) date()

2) datetime()

3) current_datetime()

4) now()

Answer : Option 1

What is the output of `echo isset($var);` where `$var` is undefined?

1) 0

2) 1

3) NULL

4) Error

Answer : Option 1