使用[]时的语法问题

时间:2013-12-11 10:01:19

标签: php syntax

因此,在进行测试项目(学习目的)时,我发现可以使用如下语法:

  

抛出新的异常($ Query-> errorInfo()[2]);

在$ Query-> errorInfo()之后注意使用[2](数组索引)。

这件事似乎也在研究爆炸等其他功能;

从什么时候开始?和/或需要什么样的特定环境才能工作?因为它似乎在我的网络服务器上正常工作,但在我的localhost xampp安装上却没有。

似乎也可以通过简单设置$ var = [2,4,5]来定义数组;

1 个答案:

答案 0 :(得分:4)

从PHP 5.4.0开始,您可以看到文档:

http://php.net/manual/en/migration54.new-features.php

Short array syntax has been added, e.g. $a = [1, 2, 3, 4];
or $a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];. 

Function array dereferencing has been added, e.g. foo()[0].