Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
What does the `str_split()` function do in PHP?
1) Splits a string into an array of characters
2) Splits a string into an array of words
3) Joins an array into a string
4) None of the above
Answer : Option 1
Which function is used to format a number as a currency string in PHP?
1) number_format()
2) currency_format()
3) format_currency()
4) money_format()
Answer : Option 1
How do you validate an email address in PHP?
1) Using `filter_var()` with `FILTER_VALIDATE_EMAIL`
2) Using `email_validate()` function
3) Using regex pattern
4) None of the above
Answer : Option 1
What is the output of `echo 10 ^ 2;` in PHP?
1) 8
2) 12
3) 10
4) Error
Answer : Option 1
Which function is used to create a new session variable in PHP?
1) $_SESSION[] assignment
2) session_add()
3) create_session_var()
4) new_session_var()
Answer : Option 1
How do you sort an array in ascending order in PHP?
1) Using `sort()`
2) Using `array_sort()`
3) Using `order()`
4) Using `asc_sort()`
Answer : Option 1
What does the `array_diff()` function do in PHP?
1) Calculates the difference between arrays
2) Finds common elements in arrays
3) Merges arrays
4) None of the above
Answer : Option 1
How do you make a file upload field mandatory in PHP?
1) Add `required` attribute to the HTML file input
2) Check if `$_FILES` is empty in PHP
3) Use `is_uploaded_file()` function
4) All of the above
Answer : Option 1
What is the output of `echo (bool) "true";` in PHP?
1) 1
2) true
3) 0
4) false
Answer : Option 1
How do you get the last element of an array in PHP?
1) Using `end()`
2) Using `last()`
3) Using `array_last()`
4) Using `array_tail()`
Answer : Option 1