3v4l.org

run code in 300+ PHP versions simultaneously
<?php $product_details = [ "0" => [ "brand_id" => 1, "product_type" => 1, ], "1" => [ "brand_id" => 2, "product_type" => 1, ], "2" => [ "brand_id" => 1, "product_type" => 1, ], "3" => [ "brand_id" => 2, "product_type" => 1, ], ]; function sortByOrder($a, $b) { return $a['brand_id'] - $b['brand_id']; } usort($product_details, 'sortByOrder'); $result = []; foreach ($product_details as $key => $value) { $result['brand_id'.$value['brand_id']][] = $value; } extract($result); print_r($brand_id1); print_r($brand_id2);

preferences:
48.3 ms | 406 KiB | 5 Q