2013-09-29 55 views
2

我有以下輸出,並需要獲得結果下面的組的結果按月和時間(PartStart)的日期是在陣列中,我怎麼能在PHP中做到這一點? 如果有人能幫助我,謝謝,我已經試過這樣做,但不是最終的結果,我需要我如何過濾陣列以獲得以下結果

Array 
(
    [0] => stdClass Object 
     (
      [End] => September 30, 2013 21:00:00 +0000 
      [ResizeEnabled] => 
      [RightClickEnabled] => 
      [InnerHTML] => Prog 1 (PL2) - vitor.tavora - S38:51, 2 - LAI3.DEI (DS.01.09 
)`enter code here` 
      [Width] => 50 
      [BarLength] => 120 
      [ContextMenu] => 
      [PartStart] => September 30, 2013 18:00:00 +0000 
      [Text] => Prog 1 (PL2) - vitor.tavora - S38:51, 2 - LAI3.DEI (DS.01.09 
) 
      [ToolTip] => Programação I (PL2) 
Ano 1 - vitor.tavora - S38:51, 2 - LAI3.DEI (DS.01.09 
) - 18:00 - 21:00 
      [Height] => 120 
      [Left] => 0 
      [BarColor] => Blue 
      [PartEnd] => September 30, 2013 21:00:00 +0000 
      [BackgroundColor] => #FFC37B 
      [Tag] => 
      [DayIndex] => 0 
      [DeleteEnabled] => 
      [MoveEnabled] => 
      [Value] => 0 
      [ClickEnabled] => 
      [Start] => September 30, 2013 18:00:00 +0000 
      [BarStart] => 0 
      [Box] => 1 
      [Top] => 401 
     ) 

    [1] => stdClass Object 
     (
      [End] => September 30, 2013 21:00:00 +0000 
      [ResizeEnabled] => 
      [RightClickEnabled] => 
      [InnerHTML] => Prog 1 (PL1) - sonia.luz - S38:51, 2 - LAI5.DEI (D.S.01.16 
) 
      [Width] => 50 
      [BarLength] => 120 
      [ContextMenu] => 
      [PartStart] => September 30, 2013 18:00:00 +0000 
      [Text] => Prog 1 (PL1) - sonia.luz - S38:51, 2 - LAI5.DEI (D.S.01.16 
) 
      [ToolTip] => Programação I (PL1) 
Ano 1 - sonia.luz - S38:51, 2 - LAI5.DEI (D.S.01.16 
) - 18:00 - 21:00 
      [Height] => 120 
      [Left] => 50 
      [BarColor] => Blue 
      [PartEnd] => September 30, 2013 21:00:00 +0000 
      [BackgroundColor] => #FFC37B 
      [Tag] => 
      [DayIndex] => 0 
      [DeleteEnabled] => 
      [MoveEnabled] => 
      [Value] => 0 
      [ClickEnabled] => 
      [Start] => September 30, 2013 18:00:00 +0000 
      [BarStart] => 0 
      [Box] => 1 
      [Top] => 401 
     ) 

    [2] => stdClass Object 
     (
      [End] => October 1, 2013 20:00:00 +0000 
      [ResizeEnabled] => 
      [RightClickEnabled] => 
      [InnerHTML] => TComp (TP) - rvasco - S38:51, 2 - A.S2.03 
      [Width] => 100 
      [BarLength] => 80 
      [ContextMenu] => 
      [PartStart] => October 1, 2013 18:00:00 +0000 
      [Text] => TComp (TP) - rvasco - S38:51, 2 - A.S2.03 
      [ToolTip] => Tecnologia de Computadores (TP) 
Ano 1 - rvasco - S38:51, 2 - A.S2.03 - 18:00 - 20:00 
      [Height] => 80 
      [Left] => 0 
      [BarColor] => Blue 
      [PartEnd] => October 1, 2013 20:00:00 +0000 
      [BackgroundColor] => #FFC37B 
      [Tag] => 
      [DayIndex] => 1 
      [DeleteEnabled] => 
      [MoveEnabled] => 
      [Value] => 0 
      [ClickEnabled] => 
      [Start] => October 1, 2013 18:00:00 +0000 
      [BarStart] => 0 
      [Box] => 1 
      [Top] => 401 
     ) 



) 

輸出我需要:

[30]=>(
     [18:00] => (
      [0] => 'Prog 1 (PL1) - sonia.luz - S38:51, 2 - LAI5.DEI (D.S.01.16)', 
      [1] => 'Prog 1 (PL2) - vitor.tavora - S38:51, 2 - LAI3.DEI (DS.01.09)' 
     ) 
) 
    [1]=>(
     [18:00]=>(
      [0]=>'TComp (TP) - rvasco - S38:51, 2 - A.S2.03' 
     ) 
) 
+0

「Prog 1(PL1)」和「Prog 1(PL2)」是否符合9月30日結束於21:00的標準?你希望如何解決這個碰撞? – Ultimater

+0

這可能是這樣的: »月»»天[30] =>( [21:00] =>( [0] => 「PL1」 [1] => 「PL2」 ) »»»一天中的[1] =>( [18:00] =>( [0] =>「TCOMP(TP)」 ) ) – user2061186

回答

0

給這個運行:

<?php 
date_default_timezone_set('Greenwich'); 
function dateToYearMonthDayHourMin($str) 
{ 
    $o=getdate(strtotime($str)); 
    return array($o['year'],$o['mon'],$o['mday'],$o['hours'],$o['minutes']); 
} 

$data=array(); 
$data[0]=(object)array('End'=>'September 30, 2013 21:00:00 +0000','InnerHTML'=>'Prog 1 (PL2) - vitor.tavora - S38:51, 2 - LAI3.DEI (DS.01.09)`enter code here`'); 
$data[1]=(object)array('End'=>'September 30, 2013 21:00:00 +0000','InnerHTML'=>'Prog 1 (PL1) - sonia.luz - S38:51, 2 - LAI5.DEI (D.S.01.16)'); 
$data[2]=(object)array('End'=>'October 1, 2013 20:00:00 +0000','InnerHTML'=>'TComp (TP) - rvasco - S38:51, 2 - A.S2.03'); 

$calendar=array(); 
foreach($data as $o) 
{ 
    list($y,$m,$d,$hrs,$mins)=dateToYearMonthDayHourMin($o->End); 
    //$calendar[$y][$m][$d]["$hrs:".sprintf('%02d', $mins)][]=$o->InnerHTML; 
    $calendar[$d]["$hrs:".sprintf('%02d', $mins)][]=$o->InnerHTML; 
} 

echo '<pre>'.print_r($calendar,true).'</pre>'; 
+0

謝謝,這個工程,但結果可能沒有幾個月, (PL1) - sonia.luz - S38:51,2 - LAI5.DEI(DS01.16)='( [18:00] =>( [0] =>'Prog 1 ', [1] =>'Prog 1(PL2) - vitor.tavora-S38:51,2-LAI3.DEI(DS.01.09)' ) ) [1] =>('TComp(TP) - rvasco - S38:51,2 - A.S2.03' ) ) – user2061186

+0

$ calendar [$ d] [「$ hrs :「。sprintf('%02d',$ mins)] [] = $ o-> InnerHTML;工作正常,謝謝。 – user2061186

+0

編輯您的喜好。 – Ultimater

相關問題