Bird
0
0

Identify the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - Arrays
Identify the error in this PHP code:
$settings = ["theme" => "dark", "layout" = "grid"];
AThe assignment operator for the key "layout" is incorrect; it should be => instead of =
BThe array keys must be integers, not strings
CThe array should use parentheses () instead of square brackets []
DThe values must be enclosed in single quotes, not double quotes
Step-by-Step Solution
Solution:
  1. Step 1: Review key-value assignment syntax

    In PHP associative arrays, keys and values are linked using the => operator.
  2. Step 2: Identify the error

    The code uses = instead of => for the key "layout", which is a syntax error.
  3. Final Answer:

    The assignment operator for the key "layout" is incorrect; it should be => instead of = -> Option A
  4. Quick Check:

    Use => for key-value pairs in arrays [OK]
Quick Trick: Use => to assign keys to values, not = [OK]
Common Mistakes:
  • Using = instead of => for key-value pairs
  • Confusing array syntax with other languages
  • Incorrect use of quotes around keys or values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes