以一列將子數組分組並從其他列產生逗號分隔的值
簡介
簡介簡介
$array = [ ["444", "0081"], ["449", "0081"], ["451", "0081"], ["455", "2100"], ["469", "2100"] ];
簡介
array ( 0 => array ( 0 => '444,449,451', 1 => '0081', ), 1 => array ( 0 => '455,469', 1 => '2100', ), )
簡介
<code class="php">$data = []; $groups = []; foreach($data as $item){ if(!array_key_exists($item[1], $groups)){ $groups[$item[1]] = []; } $groups[$item[1]][] = $item[0]; } $structured = []; foreach($groups as $group => $values){ $structured[] = [implode(',', $values), $group]; }</code>
以上是如何按一列對子數組進行分組並從另一列產生逗號分隔值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!