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" => 1, "b" => 2];
echo $arr["b"];
A1
B2
Ca
Db
Step-by-Step Solution
Solution:
  1. Step 1: Understand array access by key

    $arr["b"] accesses the value with key "b" which is 2.
  2. Step 2: Output the value

    echo prints the value 2.
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Access by key "b" = 2 [OK]
Quick Trick: Access associative array values by their keys in brackets [OK]
Common Mistakes:
  • Confusing keys with values
  • Using wrong key in access
  • Expecting keys as output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes