我有一个 PHP 示例用于我正在尝试执行的任务。如何使用 Java 做同样的事情?你能给我一个方向吗
function buildTree($array, $parent_id) {
$arr = array();
foreach ($array as $e) {
if ($e['parent_id'] == $parent_id) {
$arr[$e['id']] = array("title" => $e['title'],
"id" => $e[$id],
"children" => array());
$submassive = buildTree($array, $e['id']);
foreach ($submassive as $x) {
$arr[$e['id']]['children'][] = $x;
}
}
}
return array_values($arr);
}