【发布时间】:2019-08-27 18:05:10
【问题描述】:
我正在编写一个选择框,其中包含来自分层 id-parent 数据库的数据。数据是这样的: id - parent_id
126 - 120
114 - 108
105 - 52
140 - 116
142 - 116
145 - 116
122 - 120
116 - 3
118 - 116
125 - 120
102 - 3
123 - 120
120 - 3
130 - 116
119 - 116
128 - 120
141 - 116
117 - 116
121 - 120
104 - 2
我需要这样组织:
array(
3 => array(
102 => array(
122, 123, 125
)
)
116...
120...
)
)
到目前为止的代码
foreach($rsCat->linha() as $cat){
append($cat, $list);
}
function append($cat, &$list){
if( array_key_exists($cat->subcat, $list) ){
$this->pendura($cat, $list[$cat->subcat]);
}
else {
$list[$cat->subcat][] = $cat->cat_id;
}
}
【问题讨论】:
-
到目前为止你有没有努力解决这个问题?
-
我尝试过,但到目前为止..