Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Arrays
What will be the output of the following PHP code?
$arr = ["fruit" => "apple", "color" => "red"];
echo $arr["color"];
Ared
Bcolor
Capple
Dfruit
Step-by-Step Solution
Solution:
  1. Step 1: Understand array key access

    Accessing $arr["color"] returns the value for key "color".
  2. Step 2: Identify the value for key "color"

    Value is "red", so echo outputs "red".
  3. Final Answer:

    red -> Option A
  4. Quick Check:

    Key "color" = "red" [OK]
Quick Trick: Access values by keys with $array["key"] [OK]
Common Mistakes:
  • Confusing keys and values
  • Using wrong quotes or missing quotes
  • Trying to access with dot notation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes