阵中最后一个元素后面没有逗号? [英] No comma after last element in array?

查看:260
本文介绍了阵中最后一个元素后面没有逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,某些阵列不具备的最后一个项目后,一个逗号。我有一个数组:

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

$first_name = array(
              'name'        => 'first_name',
              'id'          => 'first_name',
              'maxlength'   => '20',             
              'class'       => 'text',
              'placeholder' => 'First name',
            );

我有一个逗号,但没有PHP的错误。我应该保留或删除逗号?

I have a comma but no php errors. Should I keep or remove the comma?

推荐答案

这是因为其他地方提到一种风格preference,但是我会建议调理自己免受并称尾随逗号在PHP中,因为它在语法上是无效的一些语言。特别是,我想的Internet Explorer的处理在Javascript这些类型的尾随逗号,这是非常困难的错误,当脚本在IE中失败,而成功在其他地方找到的。这也将打破JSON的有效性,是无效的SQL SELECT 名单,以及其他潜在的问题。

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.

再次,这是preference的问题,但可能会导致你在其他方面的问题。

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

这篇关于阵中最后一个元素后面没有逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆