3v4l.org

run code in 300+ PHP versions simultaneously
<?php $products = array( 33 => array( 31 => array( 'model' => 'Product 4', 'product_id' => 31, 'sku' => '', 'ean' => '1234', 'price' => '80.0000' ), 8733 => array( 'model' => 'qqq', 'product_id' => 8733, 'sku' => '', 'ean' => '1000', 'price' => '344.6281' ) ), 25 => array( 30 => array( 'model' => 'Product 3', 'product_id' => 30, 'sku' => '', 'ean' => '250', 'price' => '50.4132' ), 31 => array( 'model' => 'Product 4', 'product_id' => 31, 'sku' => '', 'ean' => '1234', 'price' => '80.0000' ) ) ); // Create a new array to store unique products $uniqueProducts = array(); foreach ($products as $parentKey => $items) { foreach ($items as $productId => $product) { $found = false; // Check if the product already exists in the uniqueProducts array foreach ($uniqueProducts as $existingItems) { if (isset($existingItems[$productId]) && $existingItems[$productId] == $product) { $found = true; break; } } // If the product is not found, add it to the uniqueProducts array if (!$found) { $uniqueProducts[$parentKey][$productId] = $product; } } } // Output the unique products array print_r($uniqueProducts);

preferences:
44.6 ms | 404 KiB | 5 Q