3 ms·
As I understand, it goes like this: in PHP grammar, expressions are divided into two classes: variables, and expressions without variables. To simplify, you can
by sanxiyn 14y ago
As I understand, it goes like this: in PHP grammar, expressions are divided into two classes: variables, and expressions without variables. To simplify, you can think variables start with $, expressions without variables don't. These two classes are handled in completely different ways. Since array literals are expressions without variables, it isn't too strange that $x[0] parses, but [0][0] doesn't.
One reason it is like that has to do with string interpolation. PHP interpolates $x[0] inside double quotes, but does not (and probably should not) interpolate [0][0]. I am not saying this is a good solution, but hopefully that answers "how is that even possible?" question.