How to create an array by values?

Good evening! There is an array:
$arr = [

 1 => [
 'name' => 'User1',
 'post' => '100',
 'summ' => '7000',

],

 2 => [

 'name' => 'User2',
 'post' => '200',
 'summ' => '6000',

],

 3 => [
 'name' => 'User1',
 'post' => '300',
 'summ' => '3000',

],
];

It has the same name: User1 - User1, User3-User3. I don't know how to make him here's a array:
$arr = [

 1 => [
 'name' => 'User1',

 'info' = > [
 ['post' => '100',
 'summ' => '7000',
],

[
 'post' => '300',
 'summ' => '3000',
],
]

],

 2 => [
 'name' => 'User2',
 'info' = > [
 'post' => '200',
 'summ' => '6000',
],
],

];


Tried using foreach, but it is impossible to correctly compare name and collect a new array. Know it's probably very easy to do. Thanks in advance.
June 14th 19 at 20:30
1 answer
June 14th 19 at 20:32
Solution
Well, something like:
function groupData($data, $groupBy, $groupTo) {
 $grouped = [];

 foreach ($data as $t) {
 $name = $t[$groupBy];
 $grouped[$name][$groupBy] = $name;
unset($t[$groupBy]);
 $grouped[$name][$groupTo][] = $t;
}

 return array_values($grouped);
}

$grouped = groupData($arr, 'name', 'info');
Cool, thanks! Works :) - nikita.Stracke commented on June 14th 19 at 20:35

Find more questions by tags PHP