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'
       )
  )
4

1 回答 1

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>';
于 2013-09-29T15:43:19.137 回答