Nick.h
Nick.h

Reputation: 4255

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

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?

Upvotes: 13

Views: 4834

Answers (2)

Muktadir
Muktadir

Reputation: 115

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.

Upvotes: 1

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272517

It makes it easier to append another entry at a later point in time.

Upvotes: 23

Related Questions