是否有可能引用在PHP中匿名数组的特定元素? [英] Is it possible to reference a specific element of an anonymous array in PHP?
问题描述
这可能是一个简单的问题,我恐怕答案可能是不,但是......
This is probably a simple question, and I'm afraid the answer might be "no", but...
下面是一个简单的一块code的:
Here's a simple piece of code:
function func1() {
$bt = debug_backtrace();
print "Previous function was " . $bt[1]['function'] . "\n";
}
现在......可以这样没有临时变量做了什么?在另一种语言,我可能希望能够说:
Now... Can this be done without the temporary variable? In another language, I might expect to be able to say:
function func1() {
print "Previous function was " . (debug_backtrace())[1]['function'] . "\n";
}
唉,在PHP中,这将导致一个错误:
Alas, in PHP, this results in an error:
PHP Parse error: syntax error, unexpected '[' ...
如果它不能做的,它不能做的,我会用一个临时变量,但我宁愿不要。
If it can't be done, it can't be done, and I'll use a temporary variable, but I'd rather not.
推荐答案
没有,直接间接引用是不幸的是没有在PHP的当前版本的支持,但显然将进来PHP 5.4。
No, direct dereferencing is unfortunately not supported in current versions of PHP, but will apparently come in PHP 5.4.
也可参阅&QUOT 术语问题;非关联化和QUOT;?
Also see Terminology question on "dereferencing"?.
这篇关于是否有可能引用在PHP中匿名数组的特定元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!