PHP数组的语法分析错误左方括号" [" [英] PHP Array Syntax Parse Error Left Square Bracket "["
问题描述
我有一个返回一个数组的函数。我有一个刚刚返回第一行的另一个功能,但由于某些原因,这让我使用一个中间变量,即失败:
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];
until PHP 5.4.0 and above.
这篇关于PHP数组的语法分析错误左方括号&QUOT; [&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!