已知数组:
array (
0 =>
array (
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12654172',
'total' => '615',
'snp' => '15',
'mount' => '41',
'lp_no' => 'P000000D',
),
1 =>
array (
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12647212',
'total' => '60',
'snp' => '15',
'mount' => '4',
'lp_no' => 'P000000D',
),
)能否按字段total为100为单位把数组再分为若干个新的数组?并加上序号字段在其中,比如: array (
'po_num' => '1/7',//新增字段信息
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12654172',
'total' => '615',
'snp' => '15',
'mount' => '41',
'lp_no' => 'P000000D',
),
...
)
array (
0 =>
array (
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12654172',
'total' => '615',
'snp' => '15',
'mount' => '41',
'lp_no' => 'P000000D',
),
1 =>
array (
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12647212',
'total' => '60',
'snp' => '15',
'mount' => '4',
'lp_no' => 'P000000D',
),
)能否按字段total为100为单位把数组再分为若干个新的数组?并加上序号字段在其中,比如: array (
'po_num' => '1/7',//新增字段信息
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12654172',
'total' => '615',
'snp' => '15',
'mount' => '41',
'lp_no' => 'P000000D',
),
...
)
解决方案 »
- 求学习答案
- 目前最热门的IT专业是什么
- 如何把下面的JS转换成PHP变量值?
- 有兴趣运行一下看看.
- 关于mysql中数据类型的问题,各位来帮忙解释下
- 请问这个网站的跳转方式?
- mysqlfront中填加一个用户,但是连不上mysql啊???
- 根据现象找PHP的配置错误。高手应能一口说出。
- 在php+mysql中能不能把数据库文件放到别的目录下! 急
- android post json给php,执行过php后,return 这个json给android端,然后从控制台输出json显示乱码(乱码:???)
- 关于include和include_once在使用上的意义
- apache的httpd.conf文件配置“LoadModule php5_module”和“PHPIniDir”之后,无法启动
0 =>
array (
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12654172',
'total' => '615',
'snp' => '15',
'mount' => '41',
'lp_no' => 'P000000D',
),
1 =>
array (
'po_num' => 'DYNP-770266110-00',
'plant' => 'DYNP',
'get_date' => '2013-09-09',
'cust_no' => '12647212',
'total' => '60',
'snp' => '15',
'mount' => '4',
'lp_no' => 'P000000D',
),
);
$split_num = 100;
foreach($ar as $item) {
if($item['total'] <= $split_num) {
$res[] = $item;
continue;
}
$total = $item['total'];
$n = ceil($total/$split_num);
for($i=1; $i<$n; $i++) {
$res[] = array_merge(array('po_nume' => "$i/$n"), $item, array('total' => $split_num));
}
$res[] = array_merge(array('po_nume' => "$i/$n"), $item, array('total' => $total%$split_num));
}
print_r($res);Array
(
[0] => Array
(
[po_nume] => 1/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 100
[snp] => 15
[mount] => 41
[lp_no] => P000000D
) [1] => Array
(
[po_nume] => 2/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 100
[snp] => 15
[mount] => 41
[lp_no] => P000000D
) [2] => Array
(
[po_nume] => 3/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 100
[snp] => 15
[mount] => 41
[lp_no] => P000000D
) [3] => Array
(
[po_nume] => 4/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 100
[snp] => 15
[mount] => 41
[lp_no] => P000000D
) [4] => Array
(
[po_nume] => 5/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 100
[snp] => 15
[mount] => 41
[lp_no] => P000000D
) [5] => Array
(
[po_nume] => 6/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 100
[snp] => 15
[mount] => 41
[lp_no] => P000000D
) [6] => Array
(
[po_nume] => 7/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 15
[snp] => 15
[mount] => 41
[lp_no] => P000000D
) [7] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12647212
[total] => 60
[snp] => 15
[mount] => 4
[lp_no] => P000000D
))
[6] => Array
(
[po_no] => 7/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 15
) [7] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12647212
[total] => 60
)这个能不能作为一项来处理?将原来的数组并到前一个数组中,而不是重新计算$i/$n的序列号。变成这样的形式: [6] => Array
(
[po_no] => 7/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 15
) [7] => Array
(
[po_no] => 7/7
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12647212
[total] => 60 //15+60=75 < 100
)