PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Syntax "index => values", separated by commas, define index and values. index may be of type string or integer. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.
Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.
Hmm, I would have guessed it "tells" the interpreter to expect another value after the comma, not as an optional delimiter marking the end of the current value. I guess it it makes sense now. I actually discovered it during debugging... I was copying stuff around and then saw it and was like WTF how is this even parsing? lol.. thanks for RTFMing for me.
PHP is one of the few languages that allow an extra hanging comma at the end of lists. I assume it is because in PHP you generate things like arrays, so itmakes it simpler to just concat every element with a comma at the end.
I've been using trailing commas for ages
I use a trailing comma in JS too:
[js] this.addEvents({ "updateSuccess" : true, "updateFailure" : true, "dirtyState" : true, });[/js]
Although, it's not right
Warning: trailing comma is not legal in ECMA-262 object initializers
There are 10 types of people in this world, those who understand binary and those who don't