PHP Technology & Digital Applications 5 — Questions and Answers
Question 1: What PHP function checks whether a variable is an array?
- is_array() (Correct answer)
- typeof()
- gettype() === 'array'
- array_check()
Correct answer: is_array()
is_array() returns true if the given variable is an array, making it the simplest type-check for arrays.
Question 2: Which PHP global stores files uploaded via an HTML form?
- $_POST
- $_FILES (Correct answer)
- $_UPLOAD
- $_REQUEST
Correct answer: $_FILES
$_FILES is the PHP superglobal that contains information about uploaded files, including name, type, size, and tmp_name.
Question 3: What is the purpose of PHP's `finally` block in exception handling?
- It catches all uncaught exceptions
- It executes only when no exception occurs
- It always executes after try/catch regardless of whether an exception was thrown (Correct answer)
- It re-throws exceptions to the caller
Correct answer: It always executes after try/catch regardless of whether an exception was thrown
The finally block runs whether or not an exception was thrown, making it ideal for cleanup code like closing database connections.
Question 4: Which PHP function merges two or more arrays into one?
- array_combine()
- array_push()
- array_merge() (Correct answer)
- array_concat()
Correct answer: array_merge()
array_merge() combines one or more arrays, with later arrays overwriting string keys from earlier ones.
Question 5: In PHP, what does the null coalescing operator `??` do?
- Returns true if both operands are null
- Throws an exception if the value is null
- Returns the left operand if it is set and not null, otherwise returns the right operand (Correct answer)
- Converts null to an empty string
Correct answer: Returns the left operand if it is set and not null, otherwise returns the right operand
The ?? operator returns its left-hand operand if it exists and is not null, otherwise it returns its right-hand operand.
Question 6: Which PHP function removes whitespace from the beginning and end of a string?
- strip()
- clean()
- trim() (Correct answer)
- rtrim()
Correct answer: trim()
trim() removes whitespace (spaces, tabs, newlines) from both ends of a string.
Question 7: What is the role of PHP-FPM in a web server stack?
- A PHP framework for building APIs
- A process manager that handles PHP request processing separately from the web server (Correct answer)
- A PHP package manager
- A caching layer for PHP output
Correct answer: A process manager that handles PHP request processing separately from the web server
PHP-FPM (FastCGI Process Manager) manages a pool of PHP worker processes and communicates with web servers like Nginx via FastCGI.
What PHP function checks whether a variable is an array?