配列の分割処理(整数の処理)
既知の配列 a:
array (<br /> 0 => <br /> array (<br /> 'po_num' => '20131227-000008102',<br /> 'plant' => 'JQSP',<br /> 'get_date' => '2013-12-27',<br /> 'cust_no' => '12654172',<br /> 'total' => '225',<br /> 'snp' => '15',<br /> 'mount' => '15',<br /> 'lp_no' => 'P000000D',<br /> ),<br /> )
<br /> $t = 225;<br /> $k = 0;<br /> <br /> foreach($a as $v) {<br /> $t1 = $v['total'];<br /> $v['total'] = $t1 % $t;<br /> $res[$k][] = $v;<br /> $t1 -= $v['total'];<br /> while($t1 >= $t) {<br /> $v['total'] = $t;<br /> $t1 -= $t;<br /> $res[++$k][] = $v;<br /> }<br /> }<br /> $res = array_reverse($res);<br /> print_r($res);<br />
Array<br /> (<br /> [0] => Array<br /> (<br /> [0] => Array<br /> (<br /> [po_num] => 20131227-000008102<br /> [plant] => JQSP<br /> [get_date] => 2013-12-27<br /> [cust_no] => 12654172<br /> [total] => 225<br /> [snp] => 15<br /> [mount] => 15<br /> [lp_no] => P000000D<br /> )<br /> <br /> )<br /> <br /> [1] => Array<br /> (<br /> [0] => Array<br /> (<br /> [po_num] => 20131227-000008102<br /> [plant] => JQSP<br /> [get_date] => 2013-12-27<br /> [cust_no] => 12654172<br /> [total] => 0 //产生了为0的项<br /> [snp] => 15<br /> [mount] => 15<br /> [lp_no] => P000000D<br /> )<br /> <br /> )<br /> <br /> )