函数调用后定义数组索引

Joh*_*ohn 8 php arrays function

在其他语言(如C#和JavaScript)中,我可以使用函数调用来访问数组的索引

getMyArray()[0] 
Run Code Online (Sandbox Code Playgroud)

这将允许我访问结果的第一个索引,而不是传回整个数组,然后设置结果.

但是,此快捷方式不适用于PHP.有没有办法获得这个捷径?

Joh*_*nde 15

您需要运行PHP 5.4才能使用数组取消引用.

  • 此外,这里是用于迁移到5.4的[新功能列表](http://ca.php.net/manual/en/migration54.new-features.php). (2认同)