PHP Group By Day


PHP Group By Day

给定这个数组:

    array(1) {
  [0]=>
  array(2) {
    ["Project"]=>
    array(5) {
      ["id"]=>
      string(1) "2"
      ["user_id"]=>
      string(2) "21"
      ["customer_id"]=>
      string(1) "4"
      ["name"]=>
      string(15) "WordPress Theme"
      ["created"]=>
      string(19) "2011-09-26 21:30:38"
    }
    ["Track"]=>
    array(1) {
      [0]=>
      array(8) {
        ["id"]=>
        string(1) "7"
        ["user_id"]=>
        string(2) "21"
        ["project"]=>
        string(1) "2"
        ["customer"]=>
        string(1) "4"
        ["title"]=>
        string(7) "Backend"
        ["notes"]=>
        string(0) ""
        ["created"]=>
        string(19) "2011-09-28 22:21:22"
        ["Lapse"]=>
        array(2) {
          [0]=>
          array(5) {
            ["id"]=>
            string(1) "4"
            ["track_id"]=>
            string(1) "7"
            ["start"]=>
            string(19) "2011-09-28 22:22:21"
            ["stop"]=>
            string(19) "2011-09-28 22:22:30"
            ["created"]=>
            string(19) "2011-09-28 22:22:21"
          }
          [1]=>
          array(5) {
            ["id"]=>
            string(1) "3"
            ["track_id"]=>
            string(1) "7"
            ["start"]=>
            string(19) "2011-09-28 22:22:07"
            ["stop"]=>
            string(19) "2011-09-28 22:22:12"
            ["created"]=>
            string(19) "2011-09-28 22:22:07"
          }
        }
      }
    }
  }
}

我将如何组一天在失效数组与PHP?这可能更容易直接与MySQL,但我使用CakePHP的递归函数,我不知道如何使用组By !

$list = array();
function extractByDates($arr) {
  foreach ($arr as $key => $v)
    if (is_array($v))
      function extractByDates($v);
    else if ($key == 'created')
      $list[$v] = $v;
}
extractByDates($yourGivenArray);

我没有测试!