I have two arrays. One of them is a multidimensional array e.g.
$products = array(
0 => array(
'product_id' => 33,
'variation_id' => 0,
'product_price' => 500.00
),
1 => array(
'product_id' => 45,
'variation_id' => 0,
'product_price' => 600.00
),
2 => array(
'product_id' => 48,
'variation_id' => 0,
'product_price' => 600.00
),
3 => array(
'product_id' => 49,
'variation_id' => 0,
'product_price' => 600.00
)
);
and I have a flat array
$missingItems= array(49,33);
I would like to remove items from $products where their product_id is in the array missingItems string.
$diff = array();
foreach ($missingItems as $missingItem) {
foreach ($products as $product) {
if($missingItem != $product['product_id']){
$diff[] = $missingItem;
}
}
}
echo '<pre>';
print_r($diff);
echo '</pre>';
When I do this, all the values are being repeated multiple times. e.g. if I have 4 items in my first array, and two in my second. There are 8 results. I would like only 2 to appear i.e. those that are not present in the second array.
When I have two flat arrays I use array_diff but I'm not sure how to use it in this case where I have a multidimensional array and a flat array.