Array(
[COLOR] => Red
[WEIGHT] => 20
)
Array(
[COLOR] => Red
[WEIGHT] => 25
)
Array(
[COLOR] => Red
[WEIGHT] => 30
)
Array(
[COLOR] => Green
[WEIGHT] => 20
)
Array(
[COLOR] => Green
[WEIGHT] => 25
)
Array(
[COLOR] => Green
[WEIGHT] => 30
)
// Вывод должен получиться такой.
// Red - 20, 25, 30
// Green - 20, 25, 30
$arr = [
[
'COLOR' => 'Red',
'WEIGHT' => 20
],
[
'COLOR' => 'Red',
'WEIGHT' => 25
],
[
'COLOR' => 'Red',
'WEIGHT' => 30
],
[
'COLOR' => 'Green',
'WEIGHT' => 20
],
[
'COLOR' => 'Green',
'WEIGHT' => 25
],
[
'COLOR' => 'Green',
'WEIGHT' => 30
]
];
$out = [];
foreach ($arr as $a) {
$out[$a['COLOR']][] = $a['WEIGHT'];
}
foreach (array_map(function($a){ return join(', ', $a); }, $out) as $k => $item) {
echo "$k $item<br>";
}