Array sharding (processing of integers) a: array & nbsp; (& nbsp; 0 & nbsp; & gt; & nbsp; array & nbsp; (& nbsp; po_num & nbsp; & gt; & nbsp; 20131227-000008102, & nbsp; & nbs array sharding (processing in integer format)
Known array:
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',
),
)
The processing procedure is as follows:
$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);
Result:
Array
(
[0] => Array
(
[0] => Array
(
[Po_num] => 20131227-000008102
[Plant] => JQSP
[Get_date] => 2013-12-27
[Cust_no] = & gt; 12654172
[Total] = & gt; 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] = & gt; 12654172
[Total] => 0 // A value of 0 is generated.
[Snp] => 15
[Mount] => 15
[Lp_no] => P000000D
)
)
)
Since the division is complete, there should be only one result. how can I modify the code to make it generate only non-zero items?
------ Solution --------------------
This post was last edited by xuzuning at 15:34:48 on
$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'];
if($t1 % $t) $v['total'] = $t1 % $t;
$res[$k][] = $v;
$t1 -= $v['total'];
while($t1 >= $t) {
$v['total'] = $t;