簡體   English   中英

為什么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) ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM