下面thinkphp框架教程欄目將給大家介紹關于如何按照周實現將數據分類問題,希望對需要的朋友有所幫助!
具體問題描述:
按照周將數據分類問題:
我現在有一個數據,是按照每天計算出來的tp.對應的數據為
["2011-1-1","2011-1-2","2011-1-3","2011-1-4",...]
每一天對應的數據(tp)
[1,2,2,3,...]
那么現在要講這些日期按照周分類,沒就是計算的結果為
["2011年第一周",...]
數據為
[8,...]
那么現在該怎么做呢?? 用什么語言實現都無所謂~~~~
實現方法:
<?php $date_list = null; $num_list = null; $index = 0; while($index < 20) { $date_list[] = date('Y-m-d',strtotime('-' . $index . ' day')); $num_list[] = $index; $index++; } // 先別管上面的代碼,只是為了生成你的數據 $ret_list = null; // 假設日期數組和值數組的索引一致 foreach($date_list as $k => $date) { if($ret_list[date('W', strtotime($date))]) { $ret_list[date('W', strtotime($date))] += $num_list[$k]; } else { $ret_list[date('W', strtotime($date))] = $num_list[$k]; } } echo("日期數組:<br/>"); print_r($date_list); echo("<br/>"); echo("數值數組:<br/>"); print_r($num_list); echo("<br/>"); echo("按周統(tǒng)計數組(數組的鍵就是今年的第幾周):<br/>"); print_r($ret_list);
推薦:《最新的10個thinkphp視頻教程》