Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q5 of 15
PHP - Arrays
What will this PHP code output?
$numbers = [10, 20, 30];
$numbers[] = 40;
echo count($numbers);
A3
B4
CError
D40
Step-by-Step Solution
Solution:
  1. Step 1: Understand adding elements to arrays

    $numbers[] = 40 adds 40 to the end of the array, increasing its size.
  2. Step 2: Use count() to get array length

    Original array has 3 elements, after adding one, count is 4.
  3. Final Answer:

    4 -> Option B
  4. Quick Check:

    Array length after add = 4 = C [OK]
Quick Trick: Adding with [] appends to array [OK]
Common Mistakes:
  • Thinking count stays same after adding
  • Expecting error when adding element
  • Confusing count() with sum

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes