Mark Garratt

Mark Garratt

Who am I?

Web Developer based in London, UK

What I write about

Recent Posts

Trailing array commas

This will be short post, use trailing commas in arrays.


$array = [
    'four',  // <= This comma is good

Personally I never liked this as a code style I felt it looked too much like the array was continuing when it was coming to an end. Recently it was pointed out to me that the purpose of this is for diffs, if you do not use the trailing comma there is a second line marked as edited in the diff when all it has is an added comma. Not exactly the biggest source of confusion when looking at a diff, but the more simple they can be made the better.