4 ms·
PHP handles this by having lists like this by requiring you to use an I put name like "bottle-on-a-wall[]". The brackets indicate that it should be a list. I do
by IgorPartola 12y ago
PHP handles this by having lists like this by requiring you to use an I put name like "bottle-on-a-wall[]". The brackets indicate that it should be a list. I don't hate this convention...
- andyfleming 12y agoYeah. I feel like the bracket syntax is better. The other example above isn't explicit enough, IMO.
- hayksaakian 12y agothe only problem with the bracket syntax is when it comes to nested things <form enctype='application/json'> <input name='wow[such][deep][3][much][power][!]' value='Amaze'> </form> // produces { "wow": { "such": { "deep": [ null , null , null , { "much": { "power": { "!": "Amaze" } } } ] } } }
- joesb 12y agoWhat's the problem with that? If it's deeply nested, then it's deeply nested, no matter what.
- byuu 12y agoIt's pedantic, but it's a tad clunky now: I'd use something like "wow/such/deep[3]/much/power/!" to differentiate child nodes from array indexes, and also strongly advise against a node named "!" on principle. Of course then you'd say "but I want '/' in my node name!", and then you get to bikeshed an escape sequence, but you'd need that anyway for a node name with '[' or ']' in it. However, what they've done is workable if all the browser vendors implement it.
- stephenr 12y agosquare brackets are a reasonably common way to access data in an hash-like object. both Javascript (objects) and PHP (associative arrays) use/allow square brackets for this.