Known quantity Group A:
Array ( 0 = = Array ( ' po_num ' = ' 20131227-000008102 ', ' plant ' = ' jqsp ', ' get_date ' = > ' 2013-12-27 ', ' cust_no ' = ' 12654172 ', ' total ' = ' 225 ', ' SNP ' = ' ', ' mount ' and ' = ' ' Lp_no ', ' p000000d ', ),
The handlers are as follows:
$t = 225; $k = 0;foreach ($a as $v) {$t 1 = $v [' Total '], $v [' total '] = $t 1 $t; $res [$k] = $v; $t 1-= $v [' Total '];while ($t 1 & gt;= $t) {$v [' total '] = $t; $t 1-= $t; $res [+ + $k] = $v;}} $res = Array_reverse ($res);p rint_r ($res);
The results obtained:
Array ([ 0] = = Array ( [0] = = Array ( [Po_num] = 20131227-000008102 [plant] = = JQSP [Get_date] = 2013-12-27 [cust_no] = 12654172 [Total] = 225 [SNP] [ Mount ] = [ lp_no] = p000000d ) ) [1] = = Array ( [0] = = Array ( [Po_ num] = 20131227-000008102 [Plant] = JQSP [get_date] + 2013-12-27 [cust_no] = 12654172< C22/>[total] + 0//generated for 0 [SNP] [[ Mount] = [ lp_no] = p000000d ) )
Since it is divisible, then the result should be only one, how to modify the code so that it is not 0-item generation?
Reply to discussion (solution)
Think about complexity, what you want, or you can change your mind.
This post was last edited by xuzuning on 2013-12-27 15:34:48
$a = Array ( 0 = = Array (' po_num ' = ' 20131227-000008102 ', ' plant ' = ' jqsp ', ' get_date ' = > ' 2013-12-27 ', ' cust_no ' = ' 12654172 ', ' total ' = ' 225 ', ' SNP ' = ' ', ' mount ' and ' = ' ' Lp_no ', ' p000000d ', ), $t = 225; $k = 0; foreach ($a as $v) { $t 1 = $v [' total ']; if ($t 1 $t) $v [' total '] = $t 1 $t; $res [$k] = $v; $t 1-= $v [' total ']; while ($t 1 >= $t) { $v [' total '] = $t; $t 1-= $t; $res [+ + $k] = $v; }} $res = Array_reverse ($res);p rint_r ($res);
Array ([ 0] = = Array ( [0] = = Array ( [Po_num] = 20131227-000008102 [plant] = = JQSP [Get_date] = 2013-12-27 [cust_no] = 12654172 [Total] = 225 [SNP] [ Mount ] = [Lp_no] = p000000d) ) )