Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Output and String Handling
What will be the output of the following PHP code?
$arr = [1, 2, 3];
print_r($arr);
A1 2 3
BArray: 1, 2, 3
CError: Undefined function print_r
DArray ( [0] => 1 [1] => 2 [2] => 3 )
Step-by-Step Solution
Solution:
  1. Step 1: Understand print_r function

    print_r prints human-readable information about arrays, showing keys and values.
  2. Step 2: Predict output for given array

    The array has keys 0,1,2 with values 1,2,3, so output is: Array ( [0] => 1 [1] => 2 [2] => 3 )
  3. Final Answer:

    Array ( [0] => 1 [1] => 2 [2] => 3 ) -> Option D
  4. Quick Check:

    print_r shows array structure [OK]
Quick Trick: print_r shows array keys and values clearly [OK]
Common Mistakes:
  • Expecting just values without keys
  • Confusing print_r with echo
  • Thinking print_r causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes