当使用从函数返回的数组时,如何避免PHP中的临时变量

时间:2009-11-20 08:21:03

标签: php arrays

  

可能重复:
  PHP syntax for dereferencing function result

使用下面的$tmp非常难看。有没有办法避免它?

function test()
{
  return array('a'=>1, 'b'=>2);
}

$tmp = test();
echo "This should be 2: ", $tmp['b'], "\n";

是否有某种原因是自然的

test()['b']

不起作用?

0 个答案:

没有答案