Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Array Functions
What will be the output of this PHP code?
$arr = ['a' => 5, 'b' => 10, 'c' => 15];
print_r(array_values($arr));
AArray ( [0] => 5 [1] => 10 [2] => 15 )
BArray ( [a] => 5 [b] => 10 [c] => 15 )
C[a, b, c]
DError: undefined function
Step-by-Step Solution
Solution:
  1. Step 1: Understand array_values() output

    array_values() returns a new array containing only the values from the original array, re-indexed starting at 0.
  2. Step 2: Analyze print_r output

    print_r shows values as [0] => 5, [1] => 10, [2] => 15, matching Array ( [0] => 5 [1] => 10 [2] => 15 ).
  3. Final Answer:

    Array ( [0] => 5 [1] => 10 [2] => 15 ) -> Option A
  4. Quick Check:

    array_values() output = values array [OK]
Quick Trick: array_values() returns values indexed from 0 [OK]
Common Mistakes:
  • Expecting keys in output
  • Confusing keys with values
  • Thinking it returns error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes