3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id' => 1, 'date_inserted' => '2020-09-06', 'marketplace' => 'Etsy', 'total_stickers' => 11, 'total_orders' => 8, 'total_value' => 41.619999999999997], ['id' => 2, 'date_inserted' => '2020-09-06', 'marketplace' => 'Woo', 'total_stickers' => 2, 'total_orders' => 1, 'total_value' => 7.9800000000000004], ['id' => 3, 'date_inserted' => '2020-09-06', 'marketplace' => 'eBay', 'total_stickers' => 44, 'total_orders' => 40, 'total_value' => 115.63], ['id' => 4, 'date_inserted' => '2020-09-07', 'marketplace' => 'Etsy', 'total_stickers' => 8, 'total_orders' => 4, 'total_value' => 34.920000000000002], ['id' => 5, 'date_inserted' => '2020-09-07', 'marketplace' => 'Woo', 'total_stickers' => 9, 'total_orders' => 3, 'total_value' => '52.90'], ['id' => 6, 'date_inserted' => '2020-09-07', 'marketplace' => 'eBay', 'total_stickers' => 23, 'total_orders' => 21, 'total_value' => 58.030000000000001] ]; $result = []; foreach ($array as $row) { $level1 = $row['date_inserted']; $level2 = $row['marketplace']; unset($row['date_inserted'], $row['marketplace']); $result[$level1][$level2] = $row; } var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( '2020-09-06' => array ( 'Etsy' => array ( 'id' => 1, 'total_stickers' => 11, 'total_orders' => 8, 'total_value' => 41.62, ), 'Woo' => array ( 'id' => 2, 'total_stickers' => 2, 'total_orders' => 1, 'total_value' => 7.98, ), 'eBay' => array ( 'id' => 3, 'total_stickers' => 44, 'total_orders' => 40, 'total_value' => 115.63, ), ), '2020-09-07' => array ( 'Etsy' => array ( 'id' => 4, 'total_stickers' => 8, 'total_orders' => 4, 'total_value' => 34.92, ), 'Woo' => array ( 'id' => 5, 'total_stickers' => 9, 'total_orders' => 3, 'total_value' => '52.90', ), 'eBay' => array ( 'id' => 6, 'total_stickers' => 23, 'total_orders' => 21, 'total_value' => 58.03, ), ), )

preferences:
82.01 ms | 409 KiB | 5 Q