我在php中有两个数组,一个是文件列表,另一个是uniqueid()=> (“文件”,uid,会议)
阵列1:
$madeFromFilesArray = array(
"index",
"contact",
"reportA",
"reportB",
);
阵列2:
$LoadedArray = array(
5156e1b122c2b => array("index", uid, meetings),
5156e1b122c2c => array("about", uid, meetings),
5156e1b122c2d => array("contact", uid, meetings),
5156e1b122c2e => array("reportB", uid, meetings),
);
数组1是更新的数组。 我需要将数组2与1同步,例如从数组2中删除“about”,因为它不在1中并将reportA添加到数组2,因为它在1而不在2中。 所以最后的数组是:
结果array3:
$LoadedArray = array(
5156e1b122c2b => array("index", uid, meetings),
5156e1b122c2d => array("contact", uid, meetings),
5156e1b122c2e => array("reportB", uid, meetings),
5156e1b122c2f => array("reportA", uid, meetings),
);
答案 0 :(得分:2)
这是一个解决方案,但我不知道uid
和meetings
来自何处或代表什么,所以我使用了字符串
$madeFromFilesArray = array(
"index",
"contact",
"reportA",
"reportB",
);
$LoadedArray = array(
'5156e1b122c2b' => array("index", 'uid', 'meetings'),
'5156e1b122c2c' => array("about", 'uid', 'meetings'),
'5156e1b122c2d' => array("contact", 'uid', 'meetings'),
'5156e1b122c2e' => array("reportB", 'uid', 'meetings'),
);
$seenFiles = array();
foreach ($LoadedArray as $key => $values) {
if (!in_array($values[0], $madeFromFilesArray)) {
unset($LoadedArray[$key]);
} else {
$seenFiles[] = $values[0];
}
}
$missingFiles = array_diff($madeFromFilesArray, $seenFiles);
foreach ($missingFiles as $value) {
$LoadedArray[uniqid()] = array($value, 'uid', 'meetings');
}