您好,欢迎访问一九零五行业门户网

数组拆分处置(整数时的处理)

数组拆分处理(整数时的处理)
已知数组a:
array (
0 =>
array (
'po_num' => '20131227-000008102',
'plant' => 'jqsp',
'get_date' => '2013-12-27',
'cust_no' => '12654172',
'total' => '225',
'snp' => '15',
'mount' => '15',
'lp_no' => 'p000000d',
),
)
处理程序如下:
$t = 225;
$k = 0;
foreach($a as $v) {
$t1 = $v['total'];
$v['total'] = $t1 % $t;
$res[$k][] = $v;
$t1 -= $v['total'];
while($t1 >= $t) {
$v['total'] = $t;
$t1 -= $t;
$res[++$k][] = $v;
}
}
$res = array_reverse($res);
print_r($res);

得到的结果:
array
(
[0] => array
(
[0] => array
(
[po_num] => 20131227-000008102
[plant] => jqsp
[get_date] => 2013-12-27
[cust_no] => 12654172
[total] => 225
[snp] => 15
[mount] => 15
[lp_no] => p000000d
)
)
[1] => array
(
[0] => array
(
[po_num] => 20131227-000008102
[plant] => jqsp
[get_date] => 2013-12-27
[cust_no] => 12654172
[total] => 0 //产生了为0的项
[snp] => 15
[mount] => 15
[lp_no] => p000000d
)
)
)
既然是整除,那么结果应该只有一项,如何修改代码让其只有非0项生成?
分享到: 更多
------解决方案--------------------
本帖最后由 xuzuning 于 2013-12-27 15:34:48 编辑 $a = array (
  0 => 
  array (
    'po_num' => '20131227-000008102',
    'plant' => 'jqsp',

其它类似信息

推荐信息