我关注了ids
$ids = array (
0 => '1',
1 => '2',
2 => '2',
3 => '2',
4 => '1',
);
和value_ids
$value_ids = array (
0 => '',
1 => '13',
2 => '',
3 => '13',
4 => '5',
);
我想要以下输出
array (
1 =>
array (
1 => '5',
),
2 =>
array (
0 => '13',
),
);
我用过
$kma_manager_ids = $data_dump = []; // saving combination array data of KMA ID and same Manager ID
foreach ($kma_ids as $k => $v) {
$data_dump[$v][] = $manager_ids[$k];
}
array_walk($data_dump,function($v,$k) use (&$kma_manager_ids){
$kma_manager_ids[$k] = array_unique(array_filter($v));
});
我得到了以下输出,但似乎不是同时使用foreach
和array_walk
的完美方式是否有其他方法可以实现以下输出