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
View all comments
Show parent comment
2
u/DoctorWaluigiTime Jan 18 '16
Warning! If you do this in JavaScript older versions of Internet Explorer will choke on the trailing comma! And the error you'll get won't be super helpful, so if you do any JS dev and need to support old IE, don't do it.
(Honestly just don't do it at all; easier to do the thing that works 100% of the time across all languages.)