Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - Array Functions
What will be the output of the following PHP code?
$nums = [5, 10, 15];
$result = array_reduce($nums, function($carry, $item) {
    return $carry * $item;
}, 1);
echo $result;
A750
B30
C0
DError
Step-by-Step Solution
Solution:
  1. Step 1: Initial value is 1

    The reduction starts with carry = 1.
  2. Step 2: Multiply each item

    1 * 5 = 5, 5 * 10 = 50, 50 * 15 = 750.
  3. Final Answer:

    750 -> Option A
  4. Quick Check:

    Multiply all elements starting from 1 [OK]
Quick Trick: Initial carry affects multiplication result [OK]
Common Mistakes:
  • Assuming initial carry is zero
  • Using addition instead of multiplication
  • Ignoring initial value parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes