重複元素我有2個數組:1,其保存包含在名稱中包含一些數據作爲ID和2的文件名:卸下從bidemensional陣列PHP
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] => [email protected]
[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] => [email protected]
[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] => [email protected]
[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] => [email protected]
[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] => [email protected]
[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] => [email protected]
[estadocivil] => 1
[profissao] => 7
[file1] => 103138_cara.jpg
[file2] => 103138_corpo.jpg
)
我的問題是:我怎麼能刪除僅包含鍵「文件1」中保持有兩個鍵「文件1」和「文件2」
這裏的那些數組元素是我使用的代碼對我來說RGE數組:
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]);
}
}
}
你是如何合併的陣列?我真的沒有看到重複條目出現在哪裏或數據如何相關。我的意思是你*可以*只是'foreach($ array爲$ key => $ item){if(!isset($ item ['file1'],$ item ['file2'])){unset($ array [$ key]); }} - 但我認爲一個更好的解決方案是阻止首先出現的誘惑。 – DaveRandom 2012-08-06 21:20:27
對於array2中的每個條目(其中包含作爲array1中文件名稱一部分的ID),array1中可以有1或2個條目。每個array1元素幾乎總是有2個文件。 – mjpramos 2012-08-07 12:03:17
我試過這個合併。我覺得這裏是我的問題: ($ IDS是陣列1和$文件是數組2) – mjpramos 2012-08-07 12:06:31