根据月份分离数组

时间:2015-05-09 15:50:54

标签: php

我想根据月份来分离数组。

这是一个数组示例和我希望获得的输出:

Array
{
    [1] => 1:"Fruit";
    [2] => 2:"Mangoe"; 
    [3] => 3:"2015-2-5";
}

Array
{
    [1] => 1:"Fruit";
    [2] => 2:"Banana";
    [3] => 3:"2015-4-11";
}

Array
{
    [1] => 1:"Fruit";
    [2] => 2:"Orange"; 
    [3] => 3:"2015-2-10";
}

Array
{
    [1] => 1:"Fruit";
    [2] => 2:"Pineapple";
    [3] => 3:"2015-8-3";
}

目标输出:

February
Fruit:Banana
Fruit:Orange

April
Fruit:Banana

August
Fruit:Pineapple

这是我的代码:

<?php

    foreach ($results as $key => $value) 
    {
        $value = get_object_vars($value);
        $raw_slice = explode('s:', $value['rawdata']);


        //VARIABLES
        //GET TITLE
        $title_cut = explode(':"', str_replace('";', '', $raw_slice[2]));
        $title = $title_cut['1'];

        //GET DATE
        $date_cut = explode(':"', str_replace('";', '', $raw_slice[3]));
        $date_text = $date_cut['1'];



        $month = "01";
        $year = "2015";

        $start_date = "01-".$month."-".$year;
        $start_time = strtotime($start_date);

        $end_time = strtotime("+1 month", $start_time);

        for($i=$start_time; $i<$end_time; $i+=86400)
        {
           $list[] = date('Y-m-d-D', $i);
        }


        echo "<pre>";

        echo "<div class ='title'>";
        echo $title.'<br>';
        echo "</div>";

        echo "<div class ='date'>";
        echo date('F \ j,\ Y',strtotime($date_text));
        echo "</div>";


        echo "</pre>";        
    }

?>

0 个答案:

没有答案