そのため、array_merge と array_unique に関するいくつかの投稿を見てきましたが、私がやろうとしていることとまったく同じものは見当たりませんでした。私は解決策が次のようなものになると仮定しています: PHP - 名前付きの多次元配列を keyでマージダウンします。 .
イベントのクラスを詳述する Web ページを作成するために使用している配列 ($classagg) があります。私が現在使用しているコードは次のとおりです。
usort($classagg, function($a, $b) {
return strcmp($a['title'], $b['title']);
});
foreach($classagg as $out){
print "
<p>
<a class=\"education-class-list-title\" name=\"$out[presenter]\">$out[title]</a><br />
<span class=\"education-class-list-description\">$out[description]</span><br />
<span class=\"education-class-list-presenter\"> Presented by: <a href=\"/event/$out[eventType]/$out[eid]?qt-event=3#$out[presenter]\">$out[presenter]</a> </span>
</p>
";
}
すべてがうまく機能していますが、2 人のプレゼンターが同じクラスを提示しているクラスがいくつかあります。システムは CRM としてセットアップされているため、残念ながら、両方のプレゼンターを組み合わせたアプリケーションを作成することはできません。
現在の配列の単純化されたバージョンは次のようになります。
Array
(
[0] => Array
(
[title] => Class 1
[description] => This is a Class
[presenter] => John
)
[1] => Array
(
[title] => Class 2
[description] => This is a another class
[presenter] => Sue
)
[2] => Array
(
[title] => Class 1
[description] => Sally is presenting with John
[presenter] => Sally
)
)
配列 0 と 2 をマージし、タイトルを保持し、説明の 1 つ (できれば長い方) を保持し、両方の名前を保持したいと考えています。
助けていただければ幸いです。