I suspect you want something like array_udiff . This allows you to specify how to compare two arrays using the callback function. You simply create a callback that compares based on the product id.
I think this satisfies what you want, because the array_diff family of functions compares only the first array with the rest, it does not return elements that array2 (or 3 or 4) do not have this array.
<?php $products = array( 0 => array( 'product_id' => 33, 'variation_id' => 0, 'product_price' => 500.00 ), 1 => array( 'product_id' => 48, 'variation_id' => 0, 'product_price' => 600.00 ) ); $products2 = array( 1 => array( 'product_id' => 48, 'variation_id' => 0, 'product_price' => 600.00 ), 2 => array( 'product_id' => 49, 'variation_id' => 0, 'product_price' => 600.00 ) ); function compare_ids($a, $b) { return $b['product_id'] - $a['product_id']; } var_dump(array_udiff($products, $products2, "compare_ids")); ?>
Outputs:
array(1) { [0]=> array(3) { ["product_id"]=> int(33) ["variation_id"]=> int(0) ["product_price"]=> float(500) } }
source share