PHP PHP Syntax & Core Language Features 2 — Questions and Answers
Question 1: Which comparison operator in PHP checks both value AND type equality?
- ==
- =
- === (Correct answer)
- !=
Correct answer: ===
The strict equality operator === returns true only if both operands have the same value and the same data type.
Question 2: Which loop in PHP is guaranteed to execute its body at least once?
- for
- foreach
- while
- do-while (Correct answer)
Correct answer: do-while
The do-while loop executes the body first, then checks the condition, ensuring at least one execution.
Question 3: What does the array_push() function do in PHP?
- Removes the last element
- Adds one or more elements to the end of an array (Correct answer)
- Returns the first element
- Sorts the array
Correct answer: Adds one or more elements to the end of an array
array_push() appends one or more elements to the end of an array and returns the new count.
Question 4: Which PHP function converts a string to all lowercase letters?
- tolower()
- string_lower()
- strtolower() (Correct answer)
- lowercase()
Correct answer: strtolower()
strtolower() converts all alphabetic characters in a string to lowercase.
Question 5: What is the default value of an uninitialized variable in PHP?
- 0
- false
- NULL (Correct answer)
- undefined
Correct answer: NULL
In PHP, an uninitialized variable has the value NULL and type NULL.
Question 6: What does the empty() function return when passed an empty string?
- false
- true (Correct answer)
- 0
- NULL
Correct answer: true
empty() returns true for values considered empty: empty string, 0, NULL, false, empty array, or '0'.
Which comparison operator in PHP checks both value AND type equality?