<?php
$array = [
['brand' => 'ABC', 'model' => 'xyz', 'size' => 13],
['brand' => 'QWE', 'model' => 'poi', 'size' => 23],
['brand' => 'ABC', 'model' => 'xyz', 'size' => 18],
['brand' => 'QWE', 'model' => 'poi', 'size' => 23],
['brand' => 'ABC', 'model' => 'xyz', 'size' => 18],
];
$result = [];
foreach (array_unique($array, SORT_REGULAR) as $row) {
$compositeKey = $row['brand'] . '_' . $row['model'];
if (!isset($result[$compositeKey])) {
$result[$compositeKey] = $row;
} else {
$result[$compositeKey]['size'] = array_merge((array)$result[$compositeKey]['size'], [$row['size']]);
}
}
var_export($result);
preferences:
28.31 ms | 406 KiB | 5 Q