我正在编写一个递归函数来构造一个多维数组。基本上,问题如下:
function build($term){
$children = array();
foreach ( $term->children() as $child ) {
$children[] = build($child);
}
if(!count($children)){
return $term->text();
} else {
return $term->text() => $children; //obviously, this doesn't work
}
}
想法?我知道我可以重写函数的结构以使其工作,但似乎没有必要这样做。