只有变量才能在php中通过引用传递

时间:2015-06-09 09:15:33

标签: php pass-by-reference php-5.3

我有以下代码:

    $_SESSION['aParties'] = time();
    $aParties[] = $_SESSION['aParties'];
    error_log(print_r($aParties,true), 3, "/var/tmp/error.log");
    $first = reset(ksort($aParties));

数组aParties是这样的:

Array
(
  [0] => 1433841062
)

但我收到错误:

'Only variables should be passed by reference in the method ksort' 

请帮帮我! Thx提前

1 个答案:

答案 0 :(得分:2)

你需要这样做

ksort($aParties);
$first = reset($aParties);
  

注意:函数调用上没有引用符号 - 仅在函数定义上。单独的函数定义足以通过引用正确传递参数。

Check Docs