ima*_*ett 14 php arrays reference function
我有一个返回数组的函数.我有另一个函数只返回第一行,但由于某种原因,它使我使用一个中间变量,即失败:
function f1(/*some args*/) {
return /*an array*/;
}
function f2(/*some args*/) {
return f1(/*some args*/)[0];
}
Run Code Online (Sandbox Code Playgroud)
...有:
解析错误:语法错误,第10行的util.php中出现意外的'['
但是,这有效:
function f1(/*some args*/) {
return /*an array*/;
}
function f2(/*some args*/) {
$temp = f1(/*some args*/);
return $temp[0];
}
Run Code Online (Sandbox Code Playgroud)
我无法在网上找到任何相关内容(我的搜索一直被"?","{","<"等人混淆.
我是用PHP自学成才的 - 有什么理由我不能直接这样做,我错过了吗?
Ros*_* II 25
您不能使用函数数组解除引用
return f1(/*some args*/)[0];
Run Code Online (Sandbox Code Playgroud)
直到PHP 5.4.0及以上版本.
| 归档时间: |
|
| 查看次数: |
8817 次 |
| 最近记录: |