数组比对并求得对应关系,该怎么解决
程序员文章站
2022-05-04 10:32:10
...
数组比对并求得对应关系
已知数组a:
有对应关系,例如 packageno S2Y140805025 对应 lotno 4212,4214(type为ECS0-235,cust_no为12654172时)
又知数组b:
问:当数组a和b的type和cust_no相同时,数组a中的packageno对应的lotno在数组b中是否连续,如果不连续,则将packageno显示出来。
请问如何处理?
------解决方案--------------------
已知数组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; $iif(abs($c[$i] - $c[$i-1]) != 1) {
return '不连续';
}
}
return '连续';相关文章
相关视频
上一篇: 数组比对并求得对应关系