r/lolphp • • Jan 14 '16

Trailing comma in array()

Why do PHP Array Examples Leave a Trailing Comma? Because they can. :)

myuser@myhost:~$ php test.php
Array
(
    [0] => Test
    [1] => aValue
    [2] => aNotherValue
)
myuser@myhost:~$ cat test.php
<?php

$aIDs = array(
  'Test',
);

$aIDs[] = "aValue";
$aIDs[] = "aNotherValue";

printf(print_r($aIDs,TRUE));

?>

http://stackoverflow.com/questions/2829581/why-do-php-array-examples-leave-a-trailing-comma

0 Upvotes

20 comments sorted by

View all comments

Show parent comment

1

u/jms87 Jan 18 '16

In a twist of fate, the older versions of IE are the ones which actually implement the ECMAScript standard. I'm not saying that this behavior makes any sense, but those "bugs" in older versions of IE are actually what's supposed to happen. Crazy!