Php 基于值组合数组中的字段

Php 基于值组合数组中的字段,php,Php,所以,我看了几篇关于array_merge和array_unique的文章,但没有看到任何与我尝试做的完全相同的东西。我假设解决方案是这样的:,除了我使用的是字符串,我还将得到重复的键,我认为这是行不通的 我有一个数组($classagg),用于创建一个网页,详细说明事件的类。我当前使用的代码是: usort($classagg, function($a, $b) { return strcmp($a['title'], $b['title']); }); foreach($classagg

所以,我看了几篇关于array_merge和array_unique的文章,但没有看到任何与我尝试做的完全相同的东西。我假设解决方案是这样的:,除了我使用的是字符串,我还将得到重复的键,我认为这是行不通的

我有一个数组($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>
";
}
我希望合并数组0和数组2,保留标题,保留其中一个描述(最好是较长的描述),并保留两个名称


非常感谢您的帮助。

如果在if行中添加括号,效果会很好。谢谢你,你不会相信我一天有多少次像那样想念帕伦斯。。。现编辑:-)
$newArray = array();

foreach( $array as $class ) {
  if( isset( $newArray[$class['title']] ) ) {
    $presenters = explode( ', ', $newArray[$class['title']]['presenter'] );
    $presenters[] = $class['presenter'];
    $newArray[$class['title']]['presenter'] = implode( ', ', $presenters );

    $e = $newArray[$class['title']]['description'];
    $n = $class['description'];
    $newArray[$class['title']]['description'] = (strlen($n) > strlen($e) ? $n : $e);
  }
  else {
    $newArray[$class['title']] = $class;
  }
}
$newArray = array();

foreach( $array as $class ) {
  if( isset( $newArray[$class['title']] ) ) {
    $presenters = explode( ', ', $newArray[$class['title']]['presenter'] );
    $presenters[] = $class['presenter'];
    $newArray[$class['title']]['presenter'] = implode( ', ', $presenters );

    $e = $newArray[$class['title']]['description'];
    $n = $class['description'];
    $newArray[$class['title']]['description'] = (strlen($n) > strlen($e) ? $n : $e);
  }
  else {
    $newArray[$class['title']] = $class;
  }
}