<?php
// items from db
$array[] = [10, 20, 10];
$array[] = [10, 20, 201];
$array[] = [10, 20, 501];
$array[] = [10, 20, 601];
// new items
$arrayb[] = [10, 20, 10];
$arrayb[] = [10, 20, 20];
$arrayb[] = [10, 20, 50];
$arrayb[] = [10, 20, 60];
function compare(&$array,&$arrayb) {
foreach ($array as $k => $v) {
foreach ($arrayb as $k2 => $v2) {
if($v == $v2) {
unset($array[$k],$arrayb[$k2]); // removed matched items
}
}
}
}
compare($array,$arrayb);
// delete all
print_r($array);
echo '============';
// insert all
print_r($arrayb);
|
0 comments:
Post a Comment