PHP数组的语法分析错误左方括号" [" [英] PHP Array Syntax Parse Error Left Square Bracket "["

查看:154
本文介绍了PHP数组的语法分析错误左方括号" ["的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回一个数组的函数。我有一个刚刚返回第一行的另一个功能,但由于某些原因,这让我使用一个中间变量,即失败:

I have a function that returns an array. I have another function that just returns the first row, but for some reason, it makes me use an intermediate variable, i.e. this fails:

function f1(/*some args*/) {
    return /*an array*/;
}
function f2(/*some args*/) {
    return f1(/*some args*/)[0];
}

。 。 。搭配:

. . . with:

解析错误:语法错误,意想不到的'['在第10行util.php

Parse error: syntax error, unexpected '[' in util.php on line 10

不过,这个作品:

function f1(/*some args*/) {
    return /*an array*/;
}
function f2(/*some args*/) {
    $temp = f1(/*some args*/);
    return $temp[0];
}

我没能找到任何相关的联机(我的搜索一直得到人们迷茫着,{,<,?等)。

I wasn't able to find anything pertinent online (my searches kept getting confused by people with "?", "{", "<", etc.).

我是自学成才的PHP - 是有一些原因,我不能做到这一点直接,我已经错过

I'm self-taught in PHP - is there some reason why I can't do this directly that I've missed?

推荐答案

您不能使用函数数组取消引用

You can't use function array dereferencing

return f1(/*some args*/)[0];

5.4.0及以上。

until PHP 5.4.0 and above.

这篇关于PHP数组的语法分析错误左方括号&QUOT; [&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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