多次元配列を見て、「部分的な重複」を削除する関数(一番下に投稿)を作成しました。これが意味することは次のとおりです。
Array
(
[0] => Array(5,10)
[1] => Array(5,10,15)
)
最初の配列 (5, 10) のすべての要素は、2 番目の配列 (5,10,15) でも使用できるため、最初の配列を削除して、次のようにします。
Array(
[1] => Array(5,10,15)
)
私が作成した機能は非常に遅いですが、機能します。そのため、あなたの専門知識が私の機能を高速化することを期待して、あなたに頼っています。
事前にどうもありがとうございました!
$groups = array(
array(5,10),
array(5,10,15)
);
$flag = array();
//clone the groups - we now have two identical arrays with all the groups
$groupsInner = $groups;
//iterate first array of groups
foreach($groups as $index=>$group){
$flag[]=$index;
//iterate second array of groups
foreach($groupsInner as $indexInner=>$groupInner){
if(!in_array($indexInner, $flag)){
if(count($group)<count($groupInner)){
$diff = array_diff($group, $groupInner);
$array_to_be_deleted = $index;
$compared_to_array = $indexInner;
}else{
$diff = array_diff($groupInner, $group);
$array_to_be_deleted = $indexInner;
$compared_to_array = $index;
}
//no diff means they are "partly duplicates"
if(count($diff)==0){
unset($groups[$array_to_be_deleted]);
unset($groupsInner[$array_to_be_deleted]);
}
}
}
}