Induk transformasi tatasusunan PHP tiga dimensi
阿神
阿神 2017-05-16 13:16:28
0
3
350
array(2) {
  [0]=>
  array(15) {
    ["t_id"]=>
    string(2) "87"
    ["b_id"]=>
    string(2) "21"
    ["year"]=>
    string(4) "2018"
    ["01"]=>
    string(6) ",09,16"
    ["02"]=>
    NULL
    ["03"]=>
    NULL
    ["04"]=>
    NULL
    ["05"]=>
    NULL
    ["06"]=>
    NULL
    ["07"]=>
    NULL
    ["08"]=>
    NULL
    ["09"]=>
    NULL
   ["10"]=>
    string(6) ",18,18"
    ["11"]=>
    string(3) ",09"
    ["12"]=>
    NULL
  }
  [1]=>
  array(15) {
    ["t_id"]=>
    string(2) "86"
    ["b_id"]=>
    string(2) "21"
    ["year"]=>
    string(4) "2017"
    ["01"]=>
    NULL
    ["02"]=>
    NULL
    ["03"]=>
    NULL
    ["04"]=>
    string(0) ""
    ["05"]=>
    string(15) ",23,23,24,24,23"
    ["06"]=>
    string(9) ",20,12,15"
    ["07"]=>
    string(6) ",19,10"
    ["08"]=>
    string(0) ""
    ["09"]=>
    string(0) ""
    ["10"]=>
    string(6) ",18,18"
    ["11"]=>
    string(3) ",09"
    ["12"]=>
    NULL
  }
}
上面的数组是从数据库读出来的上面的year是年份 01 到 12是一月到十二月 然后,16,17,25 是日期

怎么弄成 下面的那种格式的尼!大神帮帮忙

array(
      '2017' => array(
      '04'=>array('15','20'),
      '05'=>array('05','18'),
      '11'=>array('11','19'),
     ),
    '2018' => array(
      '03'=>array('15','20'),
      '06'=>array('05','18'),
      '11'=>array('11','19'),
     ),
2017表示年份 04表示月份 15,20表示日期15日 20日
阿神
阿神

闭关修行中......

membalas semua(3)
过去多啦不再A梦
$monthRs = [];
$monthCfg = ["01","02","03","04","05","06","07","08","09","10","11","12"];
foreach($arr as $key => $val){
    
    foreach($val as $k=>$v){
        $year = $v['year'];
        if(in_array($k,$monthCfg)){
            $monthRs[$k] = explode(',',$v);
        }
        
    }
    
    $temp = [$year=>$monthRs];
    $monthRs = array_merge($monthRs,$temp);
    
}
迷茫
假设大数组为$a 那么改造方法如下
foreach($a as $k=>$v){
            $year = $v['year'];
            unset($v['t_id']);
               unset($v['b_id']);
               unset($v['year']);
            foreach ($v as $key => $value) {
                $value=  explode(",", ltrim($value,','));
                $time[$year][$key] = $value;
            }
        }
習慣沉默

Ia boleh diselesaikan dengan melaluinya sekali. .

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan