Thinkphp中如何按照周来实现将数据分类

 2815

下面给大家介绍关于如何按照周实现将数据分类问题,希望对需要的朋友有所帮助!

具体问题描述:

按照周将数据分类问题:

我现在有一个数据,是按照每天计算出来的tp.对应的数据为

  1. ["2011-1-1","2011-1-2","2011-1-3","2011-1-4",...]

每一天对应的数据(tp)

  1. [1,2,2,3,...]

那么现在要讲这些日期按照周分类,没就是计算的结果为

  1. ["2011年第一周",...]

数据为

  1. [8,...]

那么现在该怎么做呢?? 用什么语言实现都无所谓~~~~


实现方法:

  1. <?php
  2. $date_list     = null;
  3. $num_list     = null;
  4. $index = 0;
  5. while($index < 20) {
  6.     $date_list[] = date('Y-m-d',strtotime('-' . $index . ' day'));
  7.     $num_list[] = $index;
  8.     $index++;
  9. }
  10.  
  11. // 先别管上面的代码,只是为了生成你的数据
  12. $ret_list = null;
  13. // 假设日期数组和值数组的索引一致
  14. foreach($date_list as $k => $date) {
  15.     if($ret_list[date('W', strtotime($date))]) {
  16.         $ret_list[date('W', strtotime($date))] += $num_list[$k];
  17.     } else {
  18.         $ret_list[date('W', strtotime($date))] = $num_list[$k];
  19.     }
  20. }
  21. echo("日期数组:<br/>");
  22. print_r($date_list);
  23. echo("<br/>");
  24.  
  25. echo("数值数组:<br/>");
  26. print_r($num_list);
  27. echo("<br/>");
  28.  
  29. echo("按周统计数组(数组的键就是今年的第几周):<br/>");
  30. print_r($ret_list);


本文网址:https://www.zztuku.com/detail-10311.html
站长图库 - Thinkphp中如何按照周来实现将数据分类
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐