2
我想根據月份來隔離數組。基於月的隔離數組
這裏是一個陣列的樣品和輸出我希望得到:
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>";
}
?>
哪兒芒果在你預期的輸出? –
這個數組是如何創建的?好像你可以讓你的生活變得更輕鬆,如果你創建了不同的數組。 – Devon