为什么这个array_walk不能在PHP中初始化数组?

时间:2015-12-16 03:36:30

标签: php

我无法弄清楚为什么这不起作用$existingKeywordLookup

  $existingKeywords = $sharedSet->negativeKeywords;
  Yii::error("There are ".count($existingKeywords)." negative keywords.");
  $existingKeywordLookup = array(); // this is a lookup table to index the objects by the keyword attribute
  Yii::error("There are ".count($existingKeywordLookup)." existing keyword lookups.");
  array_walk($existingKeywords, function ($v) use ($existingKeywordLookup) { $existingKeywordLookup[$v->keyword] = $v; }); // create lookup table
  Yii::error("There are ".count($existingKeywordLookup)." existing keyword lookups.");

日志

2015-12-15 22:30:53 [::1][1][eai6tdgr5fjlimpfdk27taloa4][error][application] There are 15 negative keywords.
2015-12-15 22:30:53 [::1][1][eai6tdgr5fjlimpfdk27taloa4][error][application] There are 0 existing keyword lookups.
2015-12-15 22:30:53 [::1][1][eai6tdgr5fjlimpfdk27taloa4][error][application] There are 0 existing keyword lookups.

1 个答案:

答案 0 :(得分:0)

我必须使用&作为use子句。

array_walk($existingKeywords, function ($v) use (&$existingKeywordLookup) ...