-2
请帮助分组日期(dd/mm/yyyy)。 我有数据这样 01/01/2014,02/01/2014,03/01/2014,04/02/2014,05/02/2014,07/03/2014
使用PHP对日期进行分组
我想组或想要的结果是这样
1,2,3 January 2014, 04,05 Febrary 2014, 07 March 2014.
请帮助分组日期(dd/mm/yyyy)。 我有数据这样 01/01/2014,02/01/2014,03/01/2014,04/02/2014,05/02/2014,07/03/2014
使用PHP对日期进行分组
我想组或想要的结果是这样
1,2,3 January 2014, 04,05 Febrary 2014, 07 March 2014.
$raw_date = '01/01/2014,02/01/2014,03/01/2014,04/02/2014,05/02/2014,07/03/2014';
# Using DD/MM/YYYY formats strtotime understands as MM/DD/YYYY
# So replace all '/' to '-'. So strtotime understand formats as DD-MM-YYYY
$raw_date = str_replace('/', '-', $raw_date);
$separated = explode(',', $raw_date);
$collection = array();
foreach($separated as $e) {
$e = date('j|F Y', strtotime($e));
$e = explode('|', $e);
if(!isset($collection[$e[1]])) {
$collection[$e[1]] = '';
}
$collection[$e[1]] .= $e[0].",";
}
foreach ($collection as $my => $d) {
echo rtrim($d, ',') . " $my\n";
}
好极了! @ vinay-kr-sharma,但我添加了一些更多的代码把我的月语言
function groupdate($dateis){
//add my date language [ID/Indonesia]
$monthID[1]="Januari";
$monthID[2]="Pebruari";
$monthID[3]="Maret";
$monthID[4]="April";
$monthID[5]="Mei";
$monthID[6]="Juni";
$monthID[7]="Juli";
$monthID[8]="Agustus";
$monthID[9]="September";
$monthID[10]="Oktober";
$monthID[11]="Nopember";
$monthID[12]="Desember";
$raw_date = $dateis;
$raw_date = str_replace('/', '-', $raw_date);
$separated = explode(',', $raw_date);
$collection = array();
foreach($separated as $e) {
//Add Some code to put the my language month
$e = date('j', strtotime($e))."|".$monthID[date('n', strtotime($e))]." ".date('Y', strtotime($e));
$e = explode('|', $e);
if(!isset($collection[$e[1]])) {
$collection[$e[1]] = '';
}
$collection[$e[1]] .= $e[0].",";
}
$result="";
foreach ($collection as $my => $d) {
$result=$result.rtrim($d, ',') . " $my, ";
}
return rtrim($result, ', ');
};
你有没有试图通过你自己做到这一点?如果是,那么也在这里添加你的代码。我们会帮你解决这个问题。 – vinaykrsharma