aluckdog
<?php$arr = Array( '0' => ' 商城A', '1' => ' 测试项目1', '2' => ' 1000', '3' => ' 1个样品', '4' => ' 3', '5' => ' 商城B', '6' => ' 测试项目2', '7' => ' 2000', '8' => ' 2个样品', '9' => ' 4', '10' => ' 商城C', '11' => ' 测试项目3', '12' => ' 1000', '13' => ' 3个样品', '14' => ' 5', '15' => ' 商城D', '16' => '测试项目4', '17' => ' 1000', '18' => ' 4个样品', '19' => ' 6', '20' => ' 商城E', '21' => ' 测试项目5', '22' => ' 1000', '23' => ' 5个样品', '24' => ' 7',);$arr = array_chunk($arr, 5);var_export($arr);$new = array();foreach ( $arr as $key => $value ) { $newVal = array(); foreach ( $value as $k => $val ) { if($k == 0) { $newVal['title'] = $val; } if($k == 1) { $newVal['price'] = $val; } if($k == 2) { $newVal['project'] = $val; } if($k == 3) { $newVal['sum'] = $val; } if($k == 4) { $newVal['cycle'] = $val; } } $new['data'][] = $newVal;}var_export($new);die;输出结果array (0 =>array (0 => ' 商城A',1 => ' 测试项目1',2 => ' 1000',3 => ' 1个样品',4 => ' 3',),1 =>array (0 => ' 商城B',1 => ' 测试项目2',2 => ' 2000',3 => ' 2个样品',4 => ' 4',),2 =>array (0 => ' 商城C',1 => ' 测试项目3',2 => ' 1000',3 => ' 3个样品',4 => ' 5',),3 =>array (0 => ' 商城D',1 => '测试项目4',2 => ' 1000',3 => ' 4个样品',4 => ' 6',),4 =>array (0 => ' 商城E',1 => ' 测试项目5',2 => ' 1000',3 => ' 5个样品',4 => ' 7',),)处理之后输出:array ('data' =>array (0 =>array ('title' => ' 商城A','price' => ' 测试项目1','project' => ' 1000','sum' => ' 1个样品','cycle' => ' 3',),1 =>array ('title' => ' 商城B','price' => ' 测试项目2','project' => ' 2000','sum' => ' 2个样品','cycle' => ' 4',),2 =>array ('title' => ' 商城C','price' => ' 测试项目3','project' => ' 1000','sum' => ' 3个样品','cycle' => ' 5',),3 =>array ('title' => ' 商城D','price' => '测试项目4','project' => ' 1000','sum' => ' 4个样品','cycle' => ' 6',),4 =>array ('title' => ' 商城E','price' => ' 测试项目5','project' => ' 1000','sum' => ' 5个样品','cycle' => ' 7',),),)
catspeake
$arr=Array('0' => '商城A','1' => '测试项目1','2' => '1000','3' => '1个样品','4' => '3','5' => '商城B','6' => '测试项目2','7' => '2000','8' => '2个样品','9' => '4','10' => '商城C','11' => '测试项目3','12' => '1000','13' => '3个样品','14' => '5','15' => '商城D','16' => '测试项目4','17' => '1000','18' => '4个样品','19' => '6','20' => '商城E','21' => '测试项目5','22' => '1000','23' => '5个样品','24' => '7');for($i=0;$i<5;$i++){$st=$i*5;$key=($i+1)*5;foreach($arr as $k=>$v){if($k>=$st && $k<$key){$tem['data'][$i][]=$v;}}}