2011-09-28 90 views
0

鑑於此陣:PHP集團通過

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的遞歸函數,我無法弄清楚如何使用Group By!

+1

「這可能更容易直接使用MySQL,但我使用CakePHP的遞歸函數,我無法弄清楚如何使用Group By!」 ---你不能用php做到這一點;-P – zerkms

+0

我擔心。回到繪圖板... – benhowdle89

+0

我剛剛在CakePHP + GROUP +關聯上回答了[一個問題](http://stackoverflow.com/questions/7590402/cakephp-combining-recursive-and-group),你應該帶一個看。 *編輯*剛注意到另一個問題也是你的! :) – bfavaretto

回答

0
$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); 

我沒有測試!