如何过滤数组以获得以下结果

时间:2013-09-29 14:40:41

标签: php arrays associative-array stdclass

我有以下输出,并且需要获得结果按照组的结果按月和时间(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'
       )
  )

1 个答案:

答案 0 :(得分: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>';