No comma after last element in array?

后端 未结 4 1874
悲&欢浪女
悲&欢浪女 2021-01-01 19:10

I noticed that some arrays don\'t have a comma after the last item. I have an array:

$first_name = array(
              \'name\'        => \'first_name\',         


        
4条回答
  •  难免孤独
    2021-01-01 20:02

    It is a style preference as mentioned elsewhere, however I would advise to condition yourself against adding that trailing comma in PHP, as it is syntactically invalid in some languages. In particular, I'm thinking of Internet Explorer's handling of those types of trailing commas in Javascript, which are notoriously difficult bugs to locate when scripts fail in IE while succeeding everywhere else. It will also break JSON's validity, and is invalid in a SQL SELECT list, among other potential problems.

    Again, it's a matter of preference, but could cause you problems in other areas.

提交回复
热议问题