Bird
0
0

Which of the following best describes the callback function used in array_reduce?

easy📝 Conceptual Q2 of 15
PHP - Array Functions
Which of the following best describes the callback function used in array_reduce?
AA function that takes one parameter and returns a boolean
BA function that takes two parameters: carry and item, and returns the updated carry
CA function that sorts the array elements
DA function that merges two arrays
Step-by-Step Solution
Solution:
  1. Step 1: Identify callback parameters in array_reduce

    The callback receives the carry (accumulated value) and the current item.
  2. Step 2: Understand callback's return value

    The callback returns the updated carry for the next iteration.
  3. Final Answer:

    A function that takes two parameters: carry and item, and returns the updated carry -> Option B
  4. Quick Check:

    Callback signature = (carry, item) => carry [OK]
Quick Trick: Callback must return updated carry value [OK]
Common Mistakes:
  • Using a callback with only one parameter
  • Expecting callback to sort or filter
  • Not returning the carry value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes