我有一个像这样的数组:
Array ( [0] => stdClass Object ( [id] => 41 [title] => test2 [alias] => test2 [catid] => 8 [published] => 1 [introtext] =>
test2
[fulltext] => [video] => [gallery] => [extra_fields] => [] [extra_fields_search] => [created] => 2012-08-27 16:37:51 [created_by] => 62 [created_by_alias] => [checked_out] => 0 [checked_out_time] => 0000-00-00 00:00:00 [modified] => 0000-00-00 00:00:00 [modified_by] => 0 [publish_up] => 2012-08-27 16:37:51 [publish_down] => 0000-00-00 00:00:00 [trash] => 0 [access] => 1 [ordering] => 15 [featured] => 0 [featured_ordering] => 0 [image_caption] => [image_credits] => [video_caption] => [video_credits] => [hits] => 0 [params] => JParameter Object ( [_raw:protected] =>
等在该数组中(它有很多东西)。
现在显示如下
项目|日期
项目|日期
项目|日期
我想要做的是获取该数组并按聚合日期对其进行排序
有点想这样
Aggr约会
项目|日期
项目|日期
Aggr约会
项目|日期
项目|日期
这个阵列是否可以实现这一点?
答案 0 :(得分:0)
这是你在找什么?
$newArray = array();
foreach ($myArrayOfStdClasses as $key => $obj) {
$newArray[date('Y-m-d', strtotime($obj->created]))[] = array('title' => $obj->tile, 'date' => $obj->created);
}
答案 1 :(得分:0)
您可以使用usort来定义排序功能:
usort($items, function($item1, $item2){
if($item1->created == $item2->created)
return 0;
return $item1->created < $item2->created ? -1 : 1;
});
这只会对它们进行排序。然后在循环输出时输出,你可以根据日,小时,月进行聚合......