为什么不';这个array_walk的工作是在PHP中初始化一个数组


Why doesn't this array_walk work to initialize an array in 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.

对于use子句,我不得不使用&

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