Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 求数组中的对应关系

求数组中的对应关系

Jun 23, 2016 pm 02:18 PM

本帖最后由 lazygc520 于 2013-07-03 12:12:16 编辑

1

数组1:Array(    [0] => Array        (            [cust_no] => 237033AW0A            [lotno] => 3207            [lotno_count] => 360        ))数组2:Array([SU13061301033] => Array        (            [0] => Array                (                    [0] => 2013-06-19 09:00:00                    [1] => X02B                    [2] => 237033AW0A                    [3] => 15                    [4] => 14                    [5] => 210                )        )[SU13061301032] => Array        (            [0] => Array                (                    [0] => 2013-06-19 09:00:00                    [1] => X02B                    [2] => 237033AW0A                    [3] => 15                    [4] => 17                    [5] => 255                )        )[SU13061301037] => Array        (            [0] => Array                (                    [0] => 2013-06-19 09:00:00                    [1] => X11Q                    [2] => 237033AW0A                    [3] => 15                    [4] => 3                    [5] => 45                )            [1] => Array                (                    [0] => 2013-06-19 09:00:00                    [1] => X11Q                    [2] => 237033AW0A                    [3] => 15                    [4] => 2                    [5] => 30                )        ))数组3:Array(              [0] => SU13061301033              [1] => SU13061301032              [2] => SU13061301037 )

Copy after login

数组1 代表 取得的总数量。
数组2 代表 stockno(SU开头部分)时对应的数量,值为第[5]项。
数组3 代表 stockno 在数组中的序列。

能不能根据数组3的序列求得,
stockno为SU13061301033时,对应数组1中的前210项对应stockno为SU13061301033 ,
stockno为SU13061301032时,对应数组1中的剩余的项对应stockno为SU13061301033 。
依次类推这种情况。

是否存在这种对应关系?


回复讨论(解决方案)

您的 数组1 不就只有一组数据吗?

您的 数组1 不就只有一组数据吗?
这样就无法匹配是吗?数组1和数组3只有对应关系才能求得结果。

如果实在找不到对应关系的话就无法求得需要的值?

对应数组1中的 前210项 这个怎么说?

对应数组1中的 前210项 这个怎么说?
我的意思是数组3中的stockno排在前面的,比如第一项SU13061301033,对应数组2中的值是210。然后用数组1中的总数量去分配210这个值,后面的stockno用总数量-210的结果再去分配下一组值。
PS:可能结果出了问题,所以我要重新查看下sql语句。稍晚再回复您。

如果用排队,倒是可以的
但关键还是在于你数据间的依赖性

如果用排队,倒是可以的
但关键还是在于你数据间的依赖性
好的。明天麻烦你指导下。

还需要你理清思绪路
贴数据时,请帖 var_export 的结果,而不是 print_r 的结果
与人方便,与己方便

结果存储的问题吧

还需要你理清思绪路
贴数据时,请帖 var_export 的结果,而不是 print_r 的结果
与人方便,与己方便

有三张表:kw_manage,vp_barcode_2d_y,stock_detail,分别对应库存,库存对应的批次lotno,出库信息。

库存以packageno为单位入库,通过vp_barcode_2d_y这张表求得入库的packageno对应的批次lotno及数量,cust_no,出库stock_detail含有信息stock_no,对应的关系:一个stock_no对应多个cust_no和对应的数量。
例如下:

1

SU13061301012(stock_no)     A2  2013-06-19 09:00:00     B12D(3)     K25B460     237033AW0A(cust_no)     10  15  2013-06-15 15:00:00     2013-06-15 15:30:00SU13061301012(stock_no)      A2  2013-06-19 09:00:00     B12D(3)     K25B459     237033AW0A(cust_no) 10  15  2013-06-15 15:00:00     2013-06-15 15:30:00

Copy after login

PS:图中数量为10*15 (箱数*每箱的个数)
也就是说stock_no和packageno之间没有必然联系,是否可以通过按批次lotno的先入先出来处理对应关系?
或者说你需要哪部分var_export的结果?

或略具体品种,即一下的讨论值针对单一的品种
入库时有 入库批次和数量 两个属性
出库时有 出库批次和数量 两个属性

你似乎是需要统计:在某个出库批次中都是由哪些入库批次构成的

我理解的对吗?

或略具体品种,即一下的讨论值针对单一的品种
入库时有 入库批次和数量 两个属性
出库时有 出库批次和数量 两个属性

你似乎是需要统计:在某个出库批次中都是由哪些入库批次构成的

我理解的对吗?
是这样。理解正确。

通常情况,我是先正常入库,再根据出库的要求(stock_detail表)用入库的信息来匹配要求。

入库:

1

CREATE TABLE `kw_manage` (  `ID` int(11) NOT NULL auto_increment,  `username` varchar(10) NOT NULL,  `rkno` varchar(25) NOT NULL,  `packageno` varchar(20) NOT NULL,  `type` varchar(20) NOT NULL,  `cust_no` varchar(20) NOT NULL,  `snp` int(4) NOT NULL,  `wh_info` varchar(20) NOT NULL,  `date` datetime NOT NULL,  PRIMARY KEY  (`ID`),  KEY `packageno` (`packageno`),  KEY `date` (`date`)) ENGINE=MyISAM;INSERT INTO `kw_manage` VALUES (1, 'admin', '201302190001', 'VP3.0 130219001', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-27 10:56:10');INSERT INTO `kw_manage` VALUES (2, 'admin', '201302190001', 'VP3.0 130219002', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-27 10:56:12');INSERT INTO `kw_manage` VALUES (3, 'admin', '201302190001', 'VP3.0 130219003', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-27 10:56:14');INSERT INTO `kw_manage` VALUES (4, 'admin', '201302190001', 'VP3.0 130219004', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:20');INSERT INTO `kw_manage` VALUES (5, 'admin', '201302190001', 'VP3.0 130219005', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:23');INSERT INTO `kw_manage` VALUES (6, 'admin', '201302190001', 'VP3.0 130219006', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:26');INSERT INTO `kw_manage` VALUES (7, 'admin', '201302190001', 'VP3.0 130219007', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:28');INSERT INTO `kw_manage` VALUES (8, 'admin', '201302190001', 'VP3.0 130219008', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:30');INSERT INTO `kw_manage` VALUES (9, 'admin', '201302190001', 'VP3.0 130219009', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:32');INSERT INTO `kw_manage` VALUES (10, 'admin', '201302190001', 'VP3.0 130219010', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:35');INSERT INTO `kw_manage` VALUES (11, 'admin', '201302190001', 'VP3.0 130219011', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:38');INSERT INTO `kw_manage` VALUES (12, 'admin', '201302190001', 'VP3.0 130219012', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:45:42');INSERT INTO `kw_manage` VALUES (13, 'admin', '201302190002', 'VP3.0 130219013', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:06');INSERT INTO `kw_manage` VALUES (14, 'admin', '201302190002', 'VP3.0 130219014', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:09');INSERT INTO `kw_manage` VALUES (15, 'admin', '201302190002', 'VP3.0 130219015', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:11');INSERT INTO `kw_manage` VALUES (16, 'admin', '201302190002', 'VP3.0 130219016', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:13');INSERT INTO `kw_manage` VALUES (17, 'admin', '201302190002', 'VP3.0 130219017', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:15');INSERT INTO `kw_manage` VALUES (18, 'admin', '201302190002', 'VP3.0 130219018', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:18');INSERT INTO `kw_manage` VALUES (19, 'admin', '201302190002', 'VP3.0 130219019', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:19');INSERT INTO `kw_manage` VALUES (20, 'admin', '201302190002', 'VP3.0 130219020', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:22');INSERT INTO `kw_manage` VALUES (21, 'admin', '201302190002', 'VP3.0 130219021', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:27');INSERT INTO `kw_manage` VALUES (22, 'admin', '201302190002', 'VP3.0 130219022', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:30');INSERT INTO `kw_manage` VALUES (23, 'admin', '201302190002', 'VP3.0 130219023', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:33');INSERT INTO `kw_manage` VALUES (24, 'admin', '201302190002', 'VP3.0 130219024', 'BEM330-500', '23703 3AW0A', 15, 'YE-00-01', '2013-06-28 08:46:36');INSERT INTO `kw_manage` VALUES (25, 'admin', '201302190023', 'VP3.0 130219048', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:16:57');INSERT INTO `kw_manage` VALUES (26, 'admin', '201302190023', 'VP3.0 130219049', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:01');INSERT INTO `kw_manage` VALUES (27, 'admin', '201302190023', 'VP3.0 130219050', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:08');INSERT INTO `kw_manage` VALUES (28, 'admin', '201302190023', 'VP3.0 130219051', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:13');INSERT INTO `kw_manage` VALUES (29, 'admin', '201302190023', 'VP3.0 130219052', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:23');INSERT INTO `kw_manage` VALUES (30, 'admin', '201302190023', 'VP3.0 130219053', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:30');INSERT INTO `kw_manage` VALUES (31, 'admin', '201302190023', 'VP3.0 130219054', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:39');INSERT INTO `kw_manage` VALUES (32, 'admin', '201302190023', 'VP3.0 130219055', 'MEC718-000', '23710 JE22A', 15, 'YQ-00-01', '2013-07-08 11:17:54');

Copy after login

本着先进先出的原则,出库过程是这样的:
出库数量已知
遍历入库表,从 出库数量 中扣除当前入库批次的数量,直到 出库数量 小于等于 0
若 出库数量 为负,则将其绝对值加回去

本着先进先出的原则,出库过程是这样的:
出库数量已知
遍历入库表,从 出库数量 中扣除当前入库批次的数量,直到 出库数量 小于等于 0
若 出库数量 为负,则将其绝对值加回去
出库:

1

$sql4 = "select arr_time,c_type,cust_no,snp,mount,mount*snp as m_total,stock_no from `".$t."` where stock_no = '".$stockno[$j-1]."'";// echo $sql4.'<br />';  $result4 = mysql_query($sql4);  $ar = array();  while($var = mysql_fetch_array($result4,MYSQL_NUM)) {       $ar[] = $var;   }   $a = array();   foreach ($ar as $item) {    $key = array_pop($item);    if (! isset($a[$key])) $a[$key] = array();    $a[$key][] = $item;}var_xeport的结果:array ( 'SU13061301033' => array ( 0 => array ( 0 => '2013-06-19 09:00:00', 1 => 'X02B', 2 => '237033AW0A', 3 => '15', 4 => '14', 5 => '210', ), ), )

Copy after login


入库:

1

$sql = "select DISTINCT b.packageno,a.stock_no from `stock_detail` as a,`kw_manage` as b where a.stock_no = '".$stockno[$j-1]."' and a.cust_no = replace( b.cust_no, ' ', '' )";//  echo $sql.'<br />';   $result = mysql_query($sql);    $res = array(); //设置一个用于存放结果的数组 while($row = mysql_fetch_array($result,MYSQL_ASSOC))    {       $sql2 = "select lotno,count(lotno) from `vp_barcode_2d_y` where packageno = '".$row['packageno']."' group by lotno,packageno order by lotno asc";//     echo $sql2.'<br />';      $result2 = mysql_query($sql2);      $var = array();     while($row2 = mysql_fetch_array($result2,MYSQL_NUM))        {           if(isset($res[$row2[0]]))           $res[$row2[0]]['count'] += $row2[1];            else            $res[$row2[0]] = array('lotno'=>$row2[0],'count'=>$row2[1]);      }   }   ksort($res);//  print_r($res);  $arrs = array();    foreach($res as $v2)    {       $arrs[] = $v2;  }   var_export($arrs);结果:array ( 0 => array ( 'lotno' => '3207', 'count' => 360, ), )//这个结果是入库的总数量,是否要求得分别的数量?

Copy after login

你贴 入库 的代码是什么意思?

你贴 入库 的代码是什么意思?
不需要知道入库总量?如何去判定入库的批次已匹配过,不回出现在其他的stock_no的结果中?

你给的数据和代码不配套
Unknown column 'arr_time' in 'field list'

刚才出库的数据没给全,贴不下了。现在补上。

1

CREATE TABLE `stock_detail` (  `ID` int(11) NOT NULL auto_increment,`stock_no` varchar(20) NOT NULL,`adress` varchar(10) NOT NULL,`arr_time` datetime NOT NULL,`c_type` varchar(20) NOT NULL,`pu_no` varchar(20) NOT NULL,`cust_no` varchar(20) NOT NULL,`mount` int(10) NOT NULL,`snp` int(10) NOT NULL,`c1_time` datetime NOT NULL,`c2_time` datetime NOT NULL, PRIMARY KEY  (`ID`)) ENGINE=MyISAM;INSERT INTO `stock_detail` VALUES (42, 'SU13061301029', 'B', '2013-06-20 22:00:00', 'P32L', 'K25K498', '310F61VA5A', 9, 16, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (43, 'SU13061301029', 'B', '2013-06-20 22:00:00', 'P32L', 'K25K497', '310F61VA5A', 10, 16, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (44, 'SU13061301031', 'A1', '2013-06-20 09:00:00', 'X02B', 'K25B418', '237033AW0A', 14, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (45, 'SU13061301030', 'A1', '2013-06-20 09:00:00', 'X02B', 'K25B417', '237033AW0A', 17, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (46, 'SU13061301033', 'A1', '2013-06-19 09:00:00', 'X02B', 'K25B416', '237033AW0A', 14, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (47, 'SU13061301032', 'A1', '2013-06-19 09:00:00', 'X02B', 'K25B415', '237033AW0A', 17, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (48, 'SU13061301034', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B407', '237033AW0A', 6, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (49, 'SU13061301034', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B408', '237033AW0A', 9, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (50, 'SU13061301035', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B409', '237033AW0A', 7, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (51, 'SU13061301035', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B410', '237033AW0A', 9, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (52, 'SU13061301036', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B434', '237033AW0A', 3, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (53, 'SU13061301036', 'A1', '2013-06-20 09:00:00', 'X11Q', 'K25B433', '237033AW0A', 2, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (54, 'SU13061301037', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B431', '237033AW0A', 3, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (55, 'SU13061301037', 'A1', '2013-06-19 09:00:00', 'X11Q', 'K25B432', '237033AW0A', 2, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (56, 'SU13061500001', 'A1', '2013-06-20 09:00:00', 'L11K', 'C6E0085', '23703EX80A', 2, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');INSERT INTO `stock_detail` VALUES (57, 'SU13061500002', 'A1', '2013-06-20 09:00:00', 'X11Q', 'C6E0084', '237033AW0A', 1, 15, '2013-06-15 15:00:00', '2013-06-15 15:30:00');

Copy after login

你给的数据和代码不配套
Unknown column 'arr_time' in 'field list'
烦见20#

本着先进先出的原则,出库过程是这样的:
出库数量已知
遍历入库表,从 出库数量 中扣除当前入库批次的数量,直到 出库数量 小于等于 0
若 出库数量 为负,则将其绝对值加回去

烦请举个例子吧,对这句话的意思不理解。
遍历入库表,从 出库数量 中扣除当前入库批次的数量

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles