array_walk 用法的一些疑问,怎么unset的逻辑??
$config = [ 1 => ['title'=> '推荐','code' => 1], 2 => ['title'=> '奇闻1','code' => 2], 3 => ['title'=> '奇闻2','code' => 2], 4 => ['title'=> '搞笑','code' => 1] ]; array_walk($config, function($value, $key) use (&$config){ // & 注意 if($value['code'] == 1){ $config[$key] = $value['title']; } else { unset($config[$key]); } }); var_dump($config); array(3) { [1]=> string(6) "推荐" [3]=> array(2) { ["title"]=> string(7) "奇闻2" ["code"]=> int(2) } [4]=> string(6) "搞笑"}