$arr = array ( 0 = Array ( ' 1@01,02 ', ' 2@01,02 ', ' 4@all ', ' 3@01 ', ' 5@01,02,04 ', ), 1 = Array ( ' 1@01,02,03 ', ' 2@01,02,04 ', ' 3@all ', ' 4@01,02 ', ' 111@01,05 ', ' 5@03 ', ), br> 2 = = Array ( ' 1@01,02,03 ', ' 2@02,03,05 ', ' 3@all ', ' 4@01,02,03 ', ' 111@01,05 ', ' 5@03 ', ) , ); $result = Array (); foreach ($arr as $items) { if (Is_array ($items)) { foreach ($items as $item) { $item = explode (' @ ', $item); if (count ($item)! = 2) { continue; } $result [$item [0]]. = $item [1]. ', '; } } } Function rejoin (& $item, $key, $seq) { $list = Array_unique (Explode ($seq, $item)); if (in_ Array (' All ', $list)) { $item = $key. ' @ALL '; }else{ $item = $key. ' @ '. Join ($seq, $list); } } Array_walk ($result, ' rejoin ', ', '); Sort ($result); Var_export ($result); /** * Array ( * 0 = ' 111@01,05, ', * 1 = ' 1@01,02,03, ', * 2 = ' 2@01,02,04,03,05, ', * 3 = ' 3@all ', * 4 = ' 4@all ', * 5 = ' 5@01,02,04,03, ', *) */ ; |