我有 2 个数组:1 个包含名称中包含 ID 的文件名,2 个包含一些数据:
Array
(
[0] => Array
(
[file] => 103135_cara.jpg
)
[1] => Array
(
[file] => 103135_corpo.jpg
)
[2] => Array
(
[file] => 103136_cara.jpg
)
[3] => Array
(
[file] => 103136_corpo.jpg
)
Array2
(
[0] => Array
(
[id] => 103137
[nome] => Eduardo Vieira
[sexo] => 1
[datanascimento] => 1983-11-15
[morada] => R: Gothard Kaesemodel 750 ? Torre 1 - Ap 508
[localidade] => Joinville
[cp1] =>
[cp2] =>
[tlm] => 479946464
[email] => eduardo@wetzel.com.br
[estadocivil] => 1
[profissao] => 7
)
[1] => Array
(
[id] => 103138
[nome] => João Nuno Gonçalves
[sexo] => 1
[datanascimento] => 1984-08-13
[morada] => Rua Elias Garcia Nº325 6D
[localidade] => Amadora
[cp1] => 2700
[cp2] => 323
[tlm] => 964359799
[email] => joaoridebmx@yahoo.com
[estadocivil] => 1
[profissao] => 7
)
我已将数组合并为:
Array3
(
[0] => Array
(
[id] => 103137
[nome] => Eduardo Vieira
[sexo] => 1
[datanascimento] => 1983-11-15
[morada] => R: Gothard Kaesemodel 750 ? Torre 1 - Ap 508
[localidade] => Joinville
[cp1] =>
[cp2] =>
[tlm] => 479946464
[email] => eduardo@wetzel.com.br
[estadocivil] => 1
[profissao] => 7
[file1] => 103137_cara.jpg
)
[1] => Array
(
[id] => 103137
[nome] => Eduardo Vieira
[sexo] => 1
[datanascimento] => 1983-11-15
[morada] => R: Gothard Kaesemodel 750 ? Torre 1 - Ap 508
[localidade] => Joinville
[cp1] =>
[cp2] =>
[tlm] => 479946464
[email] => eduardo@wetzel.com.br
[estadocivil] => 1
[profissao] => 7
[file1] => 103137_cara.jpg
[file2] => 103137_corpo.jpg
)
[2] => Array
(
[id] => 103138
[nome] => João Nuno Gonçalves
[sexo] => 1
[datanascimento] => 1984-08-13
[morada] => Rua Elias Garcia Nº325 6D
[localidade] => Amadora
[cp1] => 2700
[cp2] => 323
[tlm] => 964359799
[email] => joaoridebmx@yahoo.com
[estadocivil] => 1
[profissao] => 7
[file1] => 103138_cara.jpg
)
[3] => Array
(
[id] => 103138
[nome] => João Nuno Gonçalves
[sexo] => 1
[datanascimento] => 1984-08-13
[morada] => Rua Elias Garcia Nº325 6D
[localidade] => Amadora
[cp1] => 2700
[cp2] => 323
[tlm] => 964359799
[email] => joaoridebmx@yahoo.com
[estadocivil] => 1
[profissao] => 7
[file1] => 103138_cara.jpg
[file2] => 103138_corpo.jpg
)
我的问题是:如何删除仅包含键 'file1' 的数组元素,保留同时具有键 'file1' 和 'file2' 的数组元素
这是我用来合并数组的代码:
foreach ($ids as $val1) {
foreach ($files as $key => $val2) {
$cara = strpos($val2['file'], $val1['id'].'_cara');
if ($cara !== false) {
$val1['file1'] = $val2['file'];
$data[] = $val1;
unset($files[$key]);
}
$corpo = strpos($val2['file'], $val1['id'].'_corpo');
if ($corpo !== false) {
$val1['file2'] = $val2['file'];
$data[] = $val1;
unset($files[$key]);
}
}
}