PHP Difference between array() and []

二次信任 提交于 2019-11-26 18:43:27
The Alpha

Following [] is supported in PHP >= 5.4:

['name' => 'test', 'id' => 'theID']

This is a short syntax only and in PHP < 5.4 it won't work.

Md. A. Barik

If you are using 5.3 or previous version then you can't use [] as an array as well as associative array. If you are using 5.4 or later version of PHP then you can use either array() or [] to create an array, associative array or even multidimensional array.

As of 2019, it has been 7 years since the [] syntax was added. That is long enough to drop array() except in old legacy programs, in my opinion.

Mahad Ali

Using php 7.2, for me it seems rather then [I am a an array] {I am an array seems to work}. Difference is between {} and []. My code

<p>
  <label for="post_category"> Cat 1 </label>
  <input type="checkbox" name="post_category{first}" value="cat1">
  <br />
  <label for="post_category{second}"> Cat 2 </label>
  <input type="checkbox" name="post_category" value="cat2">
</p>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!