<?php
$results = [
[
'id' => '1000',
'name' => 'Nurten',
'pId' => '26',
'anzahl' => '1',
'pName' => 'Fitness-Teller',
'preis' => '12.90',
],
[
'id' => '1001',
'name' => 'Kutscha',
'pId' => '94',
'anzahl' => '1',
'pName' => 'Pizza Parma',
'preis' => '12.90',
],
[
'id' => '1001',
'name' => 'Kutscha',
'pId' => '75',
'anzahl' => '1',
'pName' => 'Pizza Margherita',
'preis' => '6.50',
],
];
$out = [];
foreach ($results as $result)
{
if (!isset($out[$result['id']])) {
$out[$result['id']] = array_filter($result, function($key) {
return in_array($key, ['id','name']);
}, ARRAY_FILTER_USE_KEY);
}
$out[$result['id']]['products'][] = array_filter($result, function($key) {
return in_array($key, ['pId','anzahl','pName','preis']);
}, ARRAY_FILTER_USE_KEY);
}
print_r(array_values($out));
preferences:
23.98 ms | 402 KiB | 5 Q