foreach ($arr as k1=> $v 1) {$sql 2 = "Select Cust_no,total=sum (Mount) *snp from". $t. "Where Po_num = '". $stockno. "' and Cus T_no = ' ". $v 1[' cust_no '). ' GROUP by Cust_no,snp ', $result 2 = Mssql_query ($sql 2); $b = Array (); while ($row 2 = Mssql_fetch_ar Ray ($result 2)) {$b [] = $row 2;} foreach ($b as $var) {$num = $var [' Total '];foreach ($a as $i + = $dest) {if ($num = = 0) break;if ($dest [' cust_no ']! = $var [' Cust_no ']) continue;if ($num >= $dest [' Part_count ']) {$num-= $dest [' Part_count ']; $ress [] = $dest; $a [$i] [' Part_ Count '] = 0;} else{$dest [' part_count '] = $num; $ress [] = $dest; $a [$i] [' part_count ']-= $num; $num = 0;}}} Print_r ($ress);}
How do I reset a variable array $ress? unset () or no effect.
Reply to discussion (solution)
Didn't see where Unse was.
Please explain the requirements
Didn't see where Unse was.
Please explain the requirements
The corresponding SQL condition and the value of the array $b:
Col1:select Cust_no,total=sum (Mount) *snp from dfl_stock_detail where po_num = ' SU14031300627 ' and cust_no = ' 237033aw0a ' G Roup by Cust_no,snparray ([0] = = Array ([0] = 237033aw0a [Cust_no] = 237033aw0a [1] = = 375 [Total] + 3 )) Col2:select Cust_no,total=sum (Mount) *snp from dfl_stock_detail where po_num = ' SU14031300627 ' and cust_no = ' 237033 Rc3a ' GROUP by Cust_no,snparray ([0] = = Array ([0] = 237033rc3a [cust_no] + 237033rc3a [1] = = [Total] = > 75))
The value of the corresponding $ress is calculated according to the $b value.
But now $ress to find out, col2 or col1 results.
Unset should be able to use you see Kazakhstan program is not run to that unset, in that unset place output something to see, what reflect
Didn't see where Unse was.
Please explain the requirements
Known quantity group A:array (0 = = Array (0 = ' 12653627 ', ' cust_no ' = ' 12653627 ', 1 = ' 4069 ', ' Lotno ' =&G T ' 4069 ', 2 = +, ' part_count ' (+), 1 = = Array (0 = ' 12653627 ', ' cust_no ' = ' 1265362 7 ', 1 = ' 4071 ', ' lotno ' = ' 4071 ', 2 = 146, ' Part_count ' and 146, ' 2 = = Array (0 =&G T ' 12654172 ', ' cust_no ' = ' 12654172 ', 1 = ' 4071 ', ' lotno ' = ' 4071 ', 2 = 855, ' Part_count ' =&G T 855,), 3 = = Array (0 = ' 237033aw0a ', ' cust_no ' = ' 237033aw0a ', 1 = ' 4409 ', ' lotno ' = = ' 4409 ', 2, ' part_count ', ', ' 4 = = Array (0 = ' 237033aw0a ', ' cust_no ' = ' 237 033aw0a ', 1 = ' 4410 ', ' lotno ' = ' 4410 ', 2 = 141, ' part_count ' = 141, ' 5 = = Array ' ( 0 = ' 237033rc3a ', ' cust_no ' = ' 237033rc3a ', 1 = ' 4418 ', ' lotno ' = ' 4418 ', 2 = +, ' P Art_count ' => , 6 = + Array (0 = ' 237033tc0a ', ' cust_no ' = ' 237033tc0a ', 1 = ' 4401 ', ' lotno ' and ' = ') 4401 ', 2 = 2, ' Part_count ' and 2, ' 7 = = Array (0 = ' 237033tc0a ', ' cust_no ' = ' 237033TC ') 0A ', 1 = ' 4402 ', ' lotno ' = ' 4402 ', 2 = 1, ' Part_count ' + 1, ' 8 = = Array (0 = ' 237033tc0a ', ' cust_no ' = ' 237033tc0a ', 1 = ' 4408 ', ' lotno ' = ' 4408 ', 2 = 178, ' Part_count ' = = 178,), 9 = = Array (0 = ' 237033tc0a ', ' cust_no ' = ' 237033tc0a ', 1 = ' 4409 ', ' Lotno ' = ' 4409 ', 2 = 374, ' part_count ' = 374, ')//array Barray (0 = = Array (' cust_no ' = ' 237033AW ') 0A ', ' total ' = 375, 1 = = Array (' cust_no ' = ' 237033rc3a ', ' total ' = 75,),)
Array A matches array B when the Cust_no and number of array a satisfies the cust_no and quantity of array B. Similar results that need to be obtained by $ress are as follows:
Array ( [0] = = Array ( [cust_no] = 237033aw0a [Lotno] = 4409 [Part_count] ) [1] = = Array ( [cust_no] = 237033aw0a [Lotno] = 4410 [Part_count] = + ) [2] = = Array ( [Cust_no] = 237033rc3a [Lotno] = 4418 [Part_count] = ( )))
Can this be achieved? Or in a loop like #, what is the matching result of the corresponding array a when the array B value is? How do I reset $ress value after it is assigned?
Is that what this means? Or is there a further requirement?
$a = Array (0 = = Array (' cust_no ' = ' 12653627 ', ' lotno ' = ' 4069 ', ' part_count ' = = 19,), 1 = > Array (' cust_no ' = ' 12653627 ', ' lotno ' = ' 4071 ', ' part_count ' = 146,), 2 = = Array ( ' Cust_no ' = ' 12654172 ', ' lotno ' = ' 4071 ', ' part_count ' and ' 855 ', 3 = = Array (' Cust_no ' => ; ' 237033aw0a ', ' lotno ' = ' 4409 ', ' part_count ', ' + ', ' 4 = ' array (' cust_no ' = ' 237033aw0a ', ' Lotno ' = ' 4410 ', ' part_count ' and ' 141, ' 5 = = Array (' cust_no ' = ' 237033rc3a ', ' Lotno ' =&G T ' 4418 ', ' part_count ' (+), 6 = = Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4401 ', ' par T_count ' + 2,), 7 = = Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4402 ', ' part_count ' = 1 ,), 8 = = Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4408 ', ' part_count ' = 178,), 9 = Array (' Cust_no ' + ' 237033tc0a ', ' lotno ' = ' 4409 ', ' part_count ' = 374,); $b = Array (0 = = Array (' cust_no ' = ' 237033aw0a ', ' total ' = 375,), 1 = = Array (' Cust_no ' = ' 237033rc3a ', ' total ' = '), '), foreach ($b as $d) {$k = $d [' Cust_no ']; Reset ($a); foreach ($a as $r) {if ($k! = $r [' cust_no ']) continue; $res [] = $r; }}print_r ($res);Array
(
[0] = = Array
(
[Cust_no] = 237033aw0a
[Lotno] = 4409
[Part_count] = 300
)
[1] = = Array
(
[Cust_no] = 237033aw0a
[Lotno] = 4410
[Part_count] = 141
)
[2] = = Array
(
[Cust_no] = 237033rc3a
[Lotno] = 4418
[Part_count] = 80
)
)
Is that what this means? Or is there a further requirement?
The data for the $a corresponds to the data of.
$v 1) {$sql 2 = "Select Cust_no,total=sum (Mount) *snp from". $t. "Where Po_num = '". $stockno. "' and Cust_no = '". $v 1[' Cust_no ' ]. "' GROUP by CUST_NO,SNP"; $result 2 = Mssql_query ($sql 2), $b = Array (), while ($row 2 = Mssql_fetch_array ($result 2)) {$b [] = $ Row2;} Var_export ($b);/* array B corresponds to 2 data data 1:array (0 = = Array (0 = ' 237033aw0a ', ' cust_no ' = ' 237033aw0a ', 1 = 375, ' Total ' = 375,), data 2:array (0 = = Array (0 = ' 237033rc3a ', ' cust_no ' = ' 237033rc3a ', 1 = ' = =, '), */foreach ($b as $var) {$num = $var [' Total '];foreach ($a as $i + = $dest) {if ($num = = 0) break;if ($dest [' Cust _no ']! = $var [' cust_no ']) continue;if ($num >= $dest [' Part_count ']) {$num-= $dest [' Part_count ']; $ress [] = $dest; $a [$i [' part_count '] = 0;} else{$dest [' part_count '] = $num; $ress [] = $dest; $a [$i] [' part_count ']-= $num; $num = 0;}}} Print_r ($ress);/* Current results: First: Array ([0] = = Array ([0] = 237033aw0a[cust_no] = 237033aw0a[1] = 4409[lotno] =& Gt 4409[2] = 300[part_count] => [1] = = Array ([0] = 237033aw0a[cust_no] = 237033aw0a[1] = 4410[lotno] = 4410[2] = 141[part_count ] + 75)) Second pen: Array ([0] = = Array ([0] = 237033aw0a[cust_no] = 237033aw0a[1] = 4409[lotno] = 4409[2] =& Gt 300[part_count] [1] = = Array ([0] = 237033aw0a[cust_no] = 237033aw0a[1] = 4410[lotno] = 4410[2 ] [141[part_count] + 75)) want the data: first: Array ([0] = = Array ([cust_no] = 237033aw0a [Lotno] = 4409 [par T_count] [1] = = Array ([cust_no] = 237033aw0a [Lotno] = 4410 [Part_count] + 75)) Second stroke: ARR Ay ([0] = = Array ([cust_no] = 237033rc3a[lotno] = 4418[part_count] =)) */}?>
Some data supplements:
$arr = Array (0 + = Array (0 = ' 2014-03-19 ', ' over_time ' = ' 2014-03-19 ', 1 = ' A2 ', ' arr_adress ' = ' A2 ', 2 = ' l12f ', ' c_type ' = ' l12f ', 3 = ' SU14031300627 ', ' po_num ' = ' SU14031300627 ', 4 = ' 237 033aw0a ', ' cust_no ' = ' 237033aw0a ', 5, ' Mount ' and ' 6 ', ' SNP ' = 7 ', ' Totals ' =& Gt 375, 8 = ' 2014-03-15 ', ' late_time ' = ' 2014-03-15 ', ' 1 ' = array (0 = ' 2014-03-19 ', ' Over_time ' => ; ' 2014-03-19 ', 1 = ' A2 ', ' arr_adress ' = ' A2 ', 2 = ' l12f ', ' c_type ' = ' l12f ', 3 = ' SU14031300627 ', ' Po_num ' = ' SU14031300627 ', 4 = ' 237033rc3a ', ' cust_no ' = ' 237033rc3a ', 5 = 5, ' Mount ' = 5, 6 = 1 5, ' SNP ' = 8, 7 =, ' totals ', ' = ', ' 2014-03-15 ', ' late_time ' = ' 2014-03-15 ', ', ') $a = array ( 0 = = Array (' cust_no ' = ' 12653627 ', ' lotno ' = ' 4069 ', ' part_count ' = +,), 1 = = array (' Cust_no ' => ' 12653627 ', ' lotno ' = ' 4071 ', ' part_count ' and ' 146, ' 2 ' = ' Array (' cust_no ' = ' 12654172 ', ' Lotno ' = ' 4071 ', ' part_count ' and ' 855, ' 3 = = Array (' cust_no ' = ' 237033aw0a ', ' lotno ' = ') 4409 ', ' part_count ' (+), 4 = = Array (' cust_no ' = ' 237033aw0a ', ' lotno ' = ' 4410 ', ' par T_count ' + 141, 5 = = Array (' cust_no ' = ' 237033rc3a ', ' lotno ' = ' 4418 ', ' part_count ' = = , 6 = = Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4401 ', ' part_count ' = + 2,), 7 => ; Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4402 ', ' part_count ' = 1,), 8 = = Array (' Cust _no ' = ' 237033tc0a ', ' lotno ' = ' 4408 ', ' part_count ' = 178, 9 = = Array (' cust_no ' = ' 23 7033tc0a ', ' lotno ' = ' 4409 ', ' part_count ' and ' 374, ');
Do I #6 not meet your requirements?
If you are treating $b in groups,
foreach ($b as $d) {
$res = Array ();
Do I #6 not meet your requirements?
If you are treating $b in groups,
foreach ($b as $d) {
$res = Array ();
$ A is required to be reduced to meet the $b results. For example:
Results of $ress
Array ([0] = = Array ([cust_no] = 237033aw0a [Lotno] = 4409 [Part_count] = +) [1] = = Array ([cust_no ] = 237033aw0a [Lotno] = 4410 [Part_count] + 75))
Satisfying the results of $b
Array (0 = = Array (' cust_no ' = ' 237033aw0a ', ' total ' = + 375,),)
Do I #6 not meet your requirements?
If you are treating $b in groups,
foreach ($b as $d) {
$res = Array ();
Do I #6 not meet your requirements?
If the Cust_no field of $ A and $b is the same, how much does the number of $a part_count meet the total number of $b?
Do I #6 not meet your requirements?
Link
Similar to the problem. But $b becomes a multidimensional array.
In that post $b is also a multidimensional array
In that post $b is also a multidimensional array
But only the result set of the first one-dimensional array in $b can be obtained.
What does that mean?
$a = Array (0 = = Array (' cust_no ' = ' 12653627 ', ' lotno ' = ' 4069 ', ' part_count ' = = 19,), 1 = > Array (' cust_no ' = ' 12653627 ', ' lotno ' = ' 4071 ', ' part_count ' = 146,), 2 = = Array ( ' Cust_no ' = ' 12654172 ', ' lotno ' = ' 4071 ', ' part_count ' and ' 855 ', 3 = = Array (' Cust_no ' => ; ' 237033aw0a ', ' lotno ' = ' 4409 ', ' part_count ', ' + ', ' 4 = ' array (' cust_no ' = ' 237033aw0a ', ' Lotno ' = ' 4410 ', ' part_count ' and ' 141, ' 5 = = Array (' cust_no ' = ' 237033rc3a ', ' Lotno ' =&G T ' 4418 ', ' part_count ' (+), 6 = = Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4401 ', ' par T_count ' + 2,), 7 = = Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4402 ', ' part_count ' = 1 ,), 8 = = Array (' cust_no ' = ' 237033tc0a ', ' lotno ' = ' 4408 ', ' part_count ' = 178,), 9 = Array (' Cust_no ' + ' 237033tc0a ', ' lotno ' = ' 4409 ', ' part_count ' = 374,); $b = Array (' cust_no ' = ' 237033aw0a ', ' total ' = = 375,), array (' cust_no ' = ' 237033rc3a ', ' Total ' = 75,); foreach ($b as $source) {do {$k = 0; $num = $source [' Total ']; foreach ($a as $i = + $dest) {if ($num = = 0) break; if ($dest [' cust_no ']! = $source [' cust_no ']) continue; if ($dest [' part_count '] = = 0) continue; $k + +; if ($num >= $dest [' Part_count ']) {$num-= $dest [' Part_count ']; $res [] = $dest; $a [$i] [' part_count '] = 0; }else {$dest [' part_count '] = $num; $res [] = $dest; $a [$i] [' part_count ']-= $num; $num = 0; }}}while ($k);} Var_export ($res);
Array ( 0 = = Array ( ' cust_no ' = ' 237033aw0a ', ' lotno ' = ' 4409 ', ' part_count ' = + 300, ), 1 = = Array ( ' cust_no ' = ' 237033aw0a ', ' lotno ' = ' 4410 ', ' part_count ' = + 75 , ), 2 = = Array ( ' cust_no ' = ' 237033aw0a ', ' lotno ' = ' 4410 ', ' part_count ' = >, ), 3 = = Array ( ' cust_no ' = ' 237033rc3a ', ' lotno ' = ' 4418 ', ' Part_ Count ' = =, 4 = = Array ( ' cust_no ' = ' 237033rc3a ', ' lotno ' = ' 4418 ', ' Part_count ' = 5, ),)
What does that mean?
If only this result set is obtained: How to ask?
Array ( 0 = = Array ( ' cust_no ' = ' 237033aw0a ', ' lotno ' = ' 4409 ', ' part_count ' = + 300, ), 1 = = Array ( ' cust_no ' = ' 237033aw0a ', ' lotno ' = ' 4410 ', ' part_count ' = + 75 , ), 2 = = Array ( ' cust_no ' = ' 237033rc3a ', ' lotno ' = ' 4418 ', ' part_count ' = >, ),)
What does that mean?
May be where the problem of the program, the same code, the program and the result of the example is not the same. Let me Debug and debug first. Thank you!