$address = [" Street name"= >" Rozenlaan", "House number" = > 10, "Post code"= > 3945, " City"= >" Ham"];
echo $address ["Street name"];
I get syntax error but I can’t see where I made mistake:
(syntax error, unexpected token "=", expecting "]")
I’m a student learning so tyhank for the help.
I created an array, I expected to call the (key "Street name, and get the value Rozenlaan",
instead I get a syntax error, I’m not sure where I went wrong.
2
Answers
You have extra spaces in your definition of array.
You have:
and it should be:
Reference
It’s the space between the = and the > that is the problem.
Correct:
And although it’s not necessary, I would suggest not having spaces in your array keys:
You could also use "camel case", like streetName, houseNumber, etc.
Also, you noticed that I removed stray spaces from within the array values. Try to avoid those, as well, as they can give you grief if you’re not accounting for them by trimming them off.
Hope this helps!