尝试根据它的索引是否可以被那里整除来对数组进行分组。我已经尝试了 for 循环和 foreach 循环的各种组合以及 if($i % 3 == 0) ... 但是,它并没有按照我需要的方式输出。
这是一个大大简化的数组(原始数据包含很多高度敏感的信息......)
原始数组与此类似:
$item[0]['Section 1']['Item 2'] => 1334;
$item[1]['Section 2']['Item 3'] => 15454;
$item[2]['Section 3']['Item 4'] => 1452;
$item[3]['Section 4']['Item 5'] => 1341;
$item[4]['Section 5']['Item 6'] => 1788655;
$item[5]['Section 6']['Item 7'] => 13;
$item[6]['Section 7']['Item 8'] => 142;
$item[7]['Section 8']['Item 9'] => 15678;
$item[8]['Section 9']['Item 10'] => 15542;
$item[9]['Section 10']['Item 11'] => 16578;
$item[10]['Section 11']['Item 12'] => 18452;
$item[11]['Section 12']['Item 13'] => 16565;
我正在尝试对每 3 条记录进行分组,如下所示:
$newitem[0]['Section 1']['Item 2'] => 1334;
$newitem[0]['Section 2']['Item 3'] => 15454;
$newitem[0]['Section 3']['Item 4'] => 1452;
$newitem[1]['Section 4']['Item 5'] => 1341;
$newitem[1]['Section 5']['Item 6'] => 1788655;
$newitem[1]['Section 6']['Item 7'] => 13;
$newitem[2]['Section 7']['Item 8'] => 142;
$newitem[2]['Section 8']['Item 9'] => 15678;
$newitem[2]['Section 9']['Item 10'] => 15542;
$newitem[3]['Section 10']['Item 11'] => 16578;
$newitem[3]['Section 11']['Item 12'] => 18452;
$newitem[3]['Section 12']['Item 13'] => 16565;