Создайте группу перед тем, как поместить в foreach
для отображения в html
<?php
$yourArr = [
["id"=>1,"name"=>"name1","desc"=>"description1"],
["id"=>1,"name"=>"name1","desc"=>"description2"],
["id"=>2,"name"=>"name2","desc"=>"description3"],
["id"=>2,"name"=>"name2","desc"=>"description4"],
];
print_r($yourArr);
$neededArr = array();
foreach($yourArr as $k=>$v){
$neededArr[$v['id']]["name"] = $v["name"];
$neededArr[$v['id']]["child"][] = ["desc"=>$v["desc"]];
}
print_r($neededArr);
?>
Live Demo
Графический вид
Вывод программы:
name1 description1
description2
-----------------------------------
name2 description3
description4
-----------------------------------