欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

数组比对并求得对应关系,该怎么解决

程序员文章站 2022-04-08 18:13:12
...
数组比对并求得对应关系
已知数组a:

$a = array (
0 =>
array (
'packageno' => 'S2Y140805025',
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4212',
),
1 =>
array (
'packageno' => 'S2Y140805025',
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4214',
),
2 =>
array (
'packageno' => 'SYS140804073',
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4212',
),
3 =>
array (
'packageno' => 'SYS140804073',
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4213',
),
4 =>
array (
'packageno' => 'SYS140731064',
'type' => 'ECS1-713',
'cust_no' => '12657727',
'lotno' => '4154',
),
5 =>
array (
'packageno' => 'SYS140731064',
'type' => 'ECS1-713',
'cust_no' => '12657727',
'lotno' => '4210',
),
6 =>
array (
'packageno' => 'SYS140801090',
'type' => 'ECS1-713',
'cust_no' => '12657727',
'lotno' => '4200',
),
7 =>
array (
'packageno' => 'SYS140801090',
'type' => 'ECS1-713',
'cust_no' => '12657727',
'lotno' => '4210',
),
);


有对应关系,例如 packageno S2Y140805025 对应 lotno 4212,4214(type为ECS0-235,cust_no为12654172时)

又知数组b:

$b = array (
0 =>
array (
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4211',
),
1 =>
array (
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4212',
),
2 =>
array (
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4213',
),
3 =>
array (
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4214',
),
4 =>
array (
'type' => 'ECS0-235',
'cust_no' => '12654172',
'lotno' => '4216',
),
5 =>
array (
'type' => 'ECS1-713',
'cust_no' => '12657727',
'lotno' => '4154',
),
6 =>
array (
'type' => 'ECS1-713',
'cust_no' => '12657727',
'lotno' => '4200',
),
7 =>
array (
'type' => 'ECS1-713',
'cust_no' => '12657727',
'lotno' => '4210',
),
);


问:当数组a和b的type和cust_no相同时,数组a中的packageno对应的lotno在数组b中是否连续,如果不连续,则将packageno显示出来。

请问如何处理?
------解决方案--------------------
function foo($a, $b) {
foreach($a as $v) {
$c[] = array_search($v, $b);
}
for($i=1; $i if(abs($c[$i] - $c[$i-1]) != 1) {
return '不连续';
}
}
return '连续';
数组比对并求得对应关系,该怎么解决

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频