0

我有一个这样的数组:

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] =>  

等等在那个数组中(里面有很多东西)。

现在是这样显示的

项目 | 日期
项目 | 日期
项目 | 日期

我想要做的是获取该数组并按聚合日期对其进行排序

有人这样想

聚合日期
项目 | 日期
项目 | 日期
聚合日期
项目 | 日期
项目 | 日期

考虑到这个数组,这甚至可能吗?

4

2 回答 2

0

这是你想要的?

$newArray = array();
foreach ($myArrayOfStdClasses as $key => $obj) {
    $newArray[date('Y-m-d', strtotime($obj->created]))[] = array('title' => $obj->tile, 'date' => $obj->created);
}
于 2012-08-27T18:06:49.087 回答
0

您可以使用 usort 来定义您的排序功能:

usort($items, function($item1, $item2){
   if($item1->created == $item2->created)
      return 0;

   return $item1->created < $item2->created ? -1 : 1;
});

这只会对它们进行排序。然后在循环输出时,您可以根据天、小时、月进行聚合...

于 2012-08-27T18:17:49.667 回答