时间:2021-07-01 10:21:17 帮助过:24人阅读
foreach($arr as k1=>$v1){ $sql2 = "select cust_no,total=SUM(mount)*snp from ".$t." where po_num = '".$stockno."' and cust_no = '".$v1['cust_no']."' group by cust_no,snp"; $result2 = mssql_query($sql2); $b = array(); while($row2 = mssql_fetch_array($result2)) { $b[] = $row2; } 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);}
没有看到 unse 在哪里
请说明需求
没有看到 unse 在哪里
请说明需求
col1:select cust_no,total=SUM(mount)*snp from dfl_stock_detail where po_num = 'SU14031300627' and cust_no = '237033AW0A' group by cust_no,snpArray ( [0] => Array ( [0] => 237033AW0A [cust_no] => 237033AW0A [1] => 375 [total] => 375 ) )col2: select cust_no,total=SUM(mount)*snp from dfl_stock_detail where po_num = 'SU14031300627' and cust_no = '237033RC3A' group by cust_no,snpArray ( [0] => Array ( [0] => 237033RC3A [cust_no] => 237033RC3A [1] => 75 [total] => 75 ) )
但是现在$ress求出来,col2还是col1的结果。
unset 应该是可以用的 你看哈程序是不是跑到那个unset了 ,在那个unset处输出点东西看看,有啥子反映
没有看到 unse 在哪里
请说明需求
//已知数组a:array ( 0 => array ( 0 => '12653627', 'cust_no' => '12653627', 1 => '4069', 'lotno' => '4069', 2 => 19, 'part_count' => 19, ), 1 => array ( 0 => '12653627', 'cust_no' => '12653627', 1 => '4071', 'lotno' => '4071', 2 => 146, 'part_count' => 146, ), 2 => array ( 0 => '12654172', 'cust_no' => '12654172', 1 => '4071', 'lotno' => '4071', 2 => 855, 'part_count' => 855, ), 3 => array ( 0 => '237033AW0A', 'cust_no' => '237033AW0A', 1 => '4409', 'lotno' => '4409', 2 => 300, 'part_count' => 300, ), 4 => array ( 0 => '237033AW0A', 'cust_no' => '237033AW0A', 1 => '4410', 'lotno' => '4410', 2 => 141, 'part_count' => 141, ), 5 => array ( 0 => '237033RC3A ', 'cust_no' => '237033RC3A ', 1 => '4418', 'lotno' => '4418', 2 => 80, 'part_count' => 80, ), 6 => array ( 0 => '237033TC0A', 'cust_no' => '237033TC0A', 1 => '4401', 'lotno' => '4401', 2 => 2, 'part_count' => 2, ), 7 => array ( 0 => '237033TC0A', 'cust_no' => '237033TC0A', 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, ),)//数组barray ( 0 => array ( 'cust_no' => '237033AW0A', 'total' => 375, ), 1 => array ( 'cust_no' => '237033RC3A', 'total' => 75, ),)
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] => 75 ))
是这个意思?还是有进一步要求?
$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' => 855, ), 3 => array ( 'cust_no' => '237033AW0A', 'lotno' => '4409', 'part_count' => 300, ), 4 => array ( 'cust_no' => '237033AW0A', 'lotno' => '4410', 'part_count' => 141, ), 5 => array ( 'cust_no' => '237033RC3A', 'lotno' => '4418', 'part_count' => 80, ), 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' => '237033TC0A', 'lotno' => '4409', 'part_count' => 374, ),); $b = array ( 0 => array ( 'cust_no' => '237033AW0A', 'total' => 375, ), 1 => array ( 'cust_no' => '237033RC3A', 'total' => 75, ),);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
是这个意思?还是有进一步要求?
$v1){ $sql2 = "select cust_no,total=SUM(mount)*snp from ".$t." where po_num = '".$stockno."' and cust_no = '".$v1['cust_no']."' group by cust_no,snp"; $result2 = mssql_query($sql2); $b = array(); while($row2 = mssql_fetch_array($result2)) { $b[] = $row2; } var_export($b); /*数组b分别对应2笔数据 数据1: array ( 0 => array ( 0 => '237033AW0A', 'cust_no' => '237033AW0A', 1 => 375, 'total' => 375, ),) 数据2: array ( 0 => array ( 0 => '237033RC3A', 'cust_no' => '237033RC3A', 1 => 75, 'total' => 75, ), )) */ 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); /* 目前的结果: 第一笔: Array ( [0] => Array ( [0] => 237033AW0A [cust_no] => 237033AW0A [1] => 4409 [lotno] => 4409 [2] => 300 [part_count] => 300 ) [1] => Array ( [0] => 237033AW0A [cust_no] => 237033AW0A [1] => 4410 [lotno] => 4410 [2] => 141 [part_count] => 75 ) ) 第二笔: Array ( [0] => Array ( [0] => 237033AW0A [cust_no] => 237033AW0A [1] => 4409 [lotno] => 4409 [2] => 300 [part_count] => 300 ) [1] => Array ( [0] => 237033AW0A [cust_no] => 237033AW0A [1] => 4410 [lotno] => 4410 [2] => 141 [part_count] => 75 ) ) 希望得到的数据: 第一笔: Array ( [0] => Array ( [cust_no] => 237033AW0A [lotno] => 4409 [part_count] => 300 ) [1] => Array ( [cust_no] => 237033AW0A [lotno] => 4410 [part_count] => 75 ) ) 第二笔: Array ( [0] => Array ( [cust_no] => 237033RC3A [lotno] => 4418 [part_count] => 75 ) ) */}?>
部分数据补充:
$arr = array ( 0 => array ( 0 => '2014-03-19 11:00', 'over_time' => '2014-03-19 11:00', 1 => 'A2', 'arr_adress' => 'A2', 2 => 'L12F', 'c_type' => 'L12F', 3 => 'SU14031300627', 'po_num' => 'SU14031300627', 4 => '237033AW0A', 'cust_no' => '237033AW0A', 5 => 25, 'mount' => 25, 6 => 15, 'snp' => 15, 7 => 375, 'totals' => 375, 8 => '2014-03-15', 'late_time' => '2014-03-15', ), 1 => array ( 0 => '2014-03-19 11:00', 'over_time' => '2014-03-19 11:00', 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 => 15, 'snp' => 15, 7 => 75, 'totals' => 75, 8 => '2014-03-15', 'late_time' => '2014-03-15', ), ) $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' => 855, ), 3 => array ( 'cust_no' => '237033AW0A', 'lotno' => '4409', 'part_count' => 300, ), 4 => array ( 'cust_no' => '237033AW0A', 'lotno' => '4410', 'part_count' => 141, ), 5 => array ( 'cust_no' => '237033RC3A', 'lotno' => '4418', 'part_count' => 80, ), 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' => '237033TC0A', 'lotno' => '4409', 'part_count' => 374, ),);
我 #6 的不符合你的要求吗?
如果是要对 $b 分组对待,则
foreach($b as $d) {
$res = array();
我 #6 的不符合你的要求吗?
如果是要对 $b 分组对待,则
foreach($b as $d) {
$res = array();
我 #6 的不符合你的要求吗?
如果是要对 $b 分组对待,则
foreach($b as $d) {
$res = array();
我 #6 的不符合你的要求吗?
我 #6 的不符合你的要求吗?
在那个帖子中 $b 也是多维数组
在那个帖子中 $b 也是多维数组
这个意思?
$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' => 855, ), 3 => array ( 'cust_no' => '237033AW0A', 'lotno' => '4409', 'part_count' => 300, ), 4 => array ( 'cust_no' => '237033AW0A', 'lotno' => '4410', 'part_count' => 141, ), 5 => array ( 'cust_no' => '237033RC3A', 'lotno' => '4418', 'part_count' => 80, ), 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' => '237033TC0A', 'lotno' => '4409', 'part_count' => 374, ),); $b = array ( 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' => 66, ), 3 => array ( 'cust_no' => '237033RC3A', 'lotno' => '4418', 'part_count' => 75, ), 4 => array ( 'cust_no' => '237033RC3A', 'lotno' => '4418', 'part_count' => 5, ),)
这个意思?
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' => 75, ),)
这个意思?