- print_r: documentation ( source)
- array_values: documentation ( source)
<?php
$array = Array
(
'0' => Array
(
'product_id' => 6,
'brand_id' => 2
)
,
'1' => Array
(
'product_id' => 1,
'brand_id' => 1
)
,
'2' => Array
(
'product_id' => 5,
'brand_id' => 1
)
);
$key = 'brand_id';
$return = array();
foreach($array as $v) {
$return[$v[$key]][] = $v;
}
print_r(array_values($return));
?>