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

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 に答える
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 に答える