开发者

at what scene do we use this php array?

at what scene do we use this php array ? i have seen in many 开发者_如何学编程places like

   echo $var1[$var2[]]; 


One scenario could be something like this:

You have an array of books. Each book in turn has an array of pages.

So basically:

[
    book1 => [ page1, page2, page3 ],
    book2 => [ page1, page2, page3 ]
]


The code you have given is nonsensical, and gives this error message:

Fatal error: Cannot use [] for reading.

More generally $var2[] = "xyz" is useful for adding an element to the end of an array. It is always used on the left side of an assignment, and only ever there. Anywhere else makes no sense and causes the error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜