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);
Output for git.master_jit, git.master, rfc.property-hooks
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 ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.31 ms | 407 KiB | 5 Q