Bird
0
0

Identify the error in the following PHP code that tries to create an associative array:

medium📝 Debug Q14 of 15
PHP - Arrays
Identify the error in the following PHP code that tries to create an associative array:
$info = ["name" => "John", "age" = 25];
AMissing comma between elements
BKeys should not be in quotes
CUsing = instead of => for key-value pair
DArray must use array() syntax
Step-by-Step Solution
Solution:
  1. Step 1: Check key-value assignment syntax

    PHP requires => to assign values to keys, not =.
  2. Step 2: Locate incorrect assignment

    "age" = 25 uses = instead of =>, causing syntax error.
  3. Final Answer:

    Using = instead of => for key-value pair -> Option C
  4. Quick Check:

    Use => for key-value pairs [OK]
Quick Trick: Use =>, not =, between key and value [OK]
Common Mistakes:
  • Using single = instead of =>
  • Omitting commas between pairs
  • Not quoting string keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes