Bird
0
0

What is the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Arrays
What is the output of the following PHP code?
$a = [1, 2];
$b = [3, 4];
$result = array_merge($a, $b);
print_r($result);
A[1, 2, 3, 4]
B[3, 4, 1, 2]
C[1 => 2, 3 => 4]
DArray keys and values combined
Step-by-Step Solution
Solution:
  1. Step 1: Understand array_merge behavior

    array_merge joins arrays by appending elements of second array to first, preserving order.
  2. Step 2: Apply to given arrays

    $a = [1, 2], $b = [3, 4], merged result is [1, 2, 3, 4].
  3. Final Answer:

    [1, 2, 3, 4] -> Option A
  4. Quick Check:

    array_merge appends arrays = [1, 2, 3, 4] [OK]
Quick Trick: array_merge appends arrays in order given [OK]
Common Mistakes:
  • Thinking array_merge sorts or combines keys
  • Confusing output with associative array
  • Expecting keys to be preserved as in original arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes