数组关系匹配
}
[5]=>
array(2) {
[0]=>
string(12) "CVT121226005"
[1]=>
string(11) "310F6 1VA5A"
}
[6]=>
array(2) {
[0]=>
string(12) "CVT130530033"
[1]=>
string(11) "310F6 1VA5A"
}
[7]=>
array(2) {
[0]=>
string(12) "CVT130530034"
[1]=>
string(11) "310F6 1VA5A"
}
}
以数组a为例,$a[0][2] = 3,代表$a[0][0]为SU13080800340时,对应数组b的前3组数据,CVT121015001,CVT121015002,CVT121226001。数组a后面的项对应数组b后面的结果,依次类推。
需得到类似情况的数组:
Array(
[SU13080800340] =>
Array(
[0] => CVT121015001
[1] => CVT121015002
[2] => CVT121226001
)
)
$a = array (Array
0 =>
array (
0 => 'SU13080800340',
1 => '310F6 1VA5A',
2 => '3',
),
1 =>
array (
0 => 'SU13080800345',
1 => '310F6 1VA5A',
2 => '23',
),
2 =>
array (
0 => 'SU13080800338',
1 => '310F6 1VA5A',
2 => '3',
),
3 =>
array (
0 => 'SU13080800346',
1 => '310F6 1VA5A',
2 => '25',
),
);
//数组b
$b = array (
0 =>
array (
0 => 'CVT121015001',
1 => '310F6 1VA5A',
),
1 =>
array (
0 => 'CVT121015002',
1 => '310F6 1VA5A',
),
2 =>
array (
0 => 'CVT121226001',
1 => '310F6 1VA5A',
),
3 =>
array (
0 => 'CVT121226002',
1 => '310F6 1VA5A',
),
4 =>
array (
0 => 'CVT121226003',
1 => '310F6 1VA5A',
),
5 =>
array (
0 => 'CVT121226005',
1 => '310F6 1VA5A',
),
6 =>
array (
0 => 'CVT130530033',
1 => '310F6 1VA5A',
),
7 =>
array (
0 => 'CVT130530034',
1 => '310F6 1VA5A',
),
);
foreach($a as $v) {
$t = array();
while($v[2]-- && $b) {
if($b[0][1] == $v[1]) {
$t[] = $b[0][0];
array_shift($b);
}
}
$res[$v[0]] = $t;
}
print_r($res);
[SU13080800345] => Array
(
[0] => CVT121226002
[1] => CVT121226003
[2] => CVT121226005
[3] => CVT130530033
[4] => CVT130530034
)
[SU13080800338] => Array
(
)
[SU13080800346] => Array
(
)
)