- var_export: documentation ( source)
- array_values: documentation ( source)
<?php
$array = [
['brand' => 'ABC', 'model' => 'xyz', 'size' => 13],
['brand' => 'QWE', 'model' => 'poi', 'size' => 23],
['brand' => 'ABC', 'model' => 'xyz', 'size' => 18]
];
$result = [];
foreach ($array as $row) {
$compositeKey = $row['brand'] . '_' . $row['model'];
if (!isset($result[$compositeKey])) {
$row['size'] = (array)$row['size'];
$result[$compositeKey] = $row;
} else {
$result[$compositeKey]['size'][] = $row['size'];
}
}
var_export(array_values($result));