【发布时间】:2013-03-27 08:56:30
【问题描述】:
我正在制作一个分类系统。我已经创建了递归函数以及在列表中显示我的类别的函数 (<ul>)。列表一切正常,每个子元素都向右移动......等等......
但现在我需要对<select> 做同样的事情。这是我到目前为止所做的:
private function _toHtml(&$list, $parent=-1, $pass = 0){
$foundSome = false;
for( $i=0,$c=count($list);$i<$c;$i++ ){
$delay = '';
if( $list[$i]['parent_id']==$parent ){
if( $foundSome==false ){
$delay .= str_repeat("--", $pass);
$foundSome = true;
}
echo '<option value="'. $list[$i]['id'] .'">'. $delay . $list[$i]['name'] .'</option>';
$this->_toHtml($list,$list[$i]['id'],$pass+1);
}
}
}
问题是,这只适用于第一个子元素,其他的根本没有考虑。它看起来基本上是这样的:
Cinema
--English (sub cat for Cinema)
French (also a sub cat for Cinema)
当我期望拥有时:
Cinema
--English (sub cat for Cinema)
--French (also a sub cat for Cinema)
有什么想法吗?
感谢您的帮助
【问题讨论】:
-
你有多少关卡?应该选择父母吗?
标签: php arrays select nested option