Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - Arrays
What will be the output of the following PHP code?
$arr = ["a", "b", "c"];
echo $arr[1];
Ab
Ba
Cc
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing in PHP

    Indexed arrays start at index 0, so $arr[0] = "a", $arr[1] = "b".
  2. Step 2: Identify the value at index 1

    The code echoes $arr[1], which is "b".
  3. Final Answer:

    b -> Option A
  4. Quick Check:

    Array index 1 value = b [OK]
Quick Trick: PHP arrays start at index 0; index 1 is second element [OK]
Common Mistakes:
  • Assuming array starts at index 1
  • Confusing keys with values
  • Expecting error due to wrong index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes