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!!!
Reply to discussion (solution)
b more items than a Array_diff (b, a)
A more than B Array_diff (A, B)
An array of B is less than an array of elements $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 "";p Rint_r ($new); echo"
/*array ( [0] = A4) *///b array has an element more than a array of $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 "";p Rint_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.