Alex Rivera | Logout

Putting comma(,) at end of array.Is it a convention?

Asked 2010-10-16T19:37:01.637
13

Sometimes I see arrays like the following:


array('item1' => array(
         'subitem1',
         'subitem2',
      )

Why a comma is added at end of array wheras there is not any element after submitem2?

Edit
Report

1 Answer

1

The comma is not needed at all. But you will still find some interpreters/compilers still allowing to use it. You can think of it this way: the interpreters is allowing you to make little mistakes and wisely fixing it internally. This is just a user-friendly way. Nothing else at all.

And you should not use that extra comma because a lot of strict ones will not let you pass through! Like Internet Explorer while interpreting Javascript. But Firefox will allow it.

answered 2010-10-16T19:58:38.130

Your Answer