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 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
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 ) ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
94.06 ms | 408 KiB | 5 Q