Novice! PHP about two arrays comparison!
There are now two arrays:
A array is a product attribute obtained from the product ID to the database.
b array is the product attribute submitted by the page.
Two array contrast, with a array as the benchmark, if the B array is less than an array of elements, then delete this element in the database association id!
If the B array has one more element than the a array, add the element and the correlation ID inside the database
Ask the Great God!!!
------to solve the idea----------------------
b more items than a Array_diff (b, a)
A more than B Array_diff (A, B)
------to solve the idea----------------------
b array has one less element than array a
$a =array (' A1 ', ' A2 ', ' A3 ', ' A4 ');
$b =array (' A1 ', ' A2 ', ' A3 ');
$new =array_merge (Array_diff ($a, array_intersect ($a, $b)), Array_diff ($b, Array_intersect ($a, $b)));
echo "";
Print_r ($new);
echo "
";
/*
Array
(
[0] = A4
)
*/
b Array has one more element than array a
$a =array (' A1 ', ' A2 ', ' A3 ');
$b =array (' A1 ', ' A2 ', ' A3 ', ' B1 ', ' B2 ');
$new =array_merge (Array_diff ($a, array_intersect ($a, $b)), Array_diff ($b, Array_intersect ($a, $b)));
echo "";
Print_r ($new);
echo "
";
/*
Array
(
[0] = B1
[1] = B2
)
*/
In contrast to the $ A array with the $new array, it's up to you to add or subtract.