Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Array Functions
What will be the output of the following PHP code?
$arr = ['a' => 1, 'b' => 2, 'c' => 3];
print_r(array_keys($arr));
AArray ( [0] => 1 [1] => 2 [2] => 3 )
BArray ( [0] => 'a' [1] => 'b' [2] => 'c' )
CArray ( [a] => 1 [b] => 2 [c] => 3 )
DArray ( [0] => a [1] => b [2] => c )
Step-by-Step Solution
Solution:
  1. Step 1: Understand array_keys() output

    It returns an indexed array of all keys from the input array.
  2. Step 2: Analyze given array keys

    Keys are strings 'a', 'b', 'c', so output is an indexed array with these strings.
  3. Final Answer:

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

    array_keys(['a'=>1,...]) = ['a','b','c'] [OK]
Quick Trick: array_keys() returns keys as indexed array [OK]
Common Mistakes:
  • Confusing keys with values in output
  • Expecting associative array output
  • Including quotes in output keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes