Created
September 14, 2016 16:59
-
-
Save mig1098/51900d0699937b06cafa088072ac61b9 to your computer and use it in GitHub Desktop.
using bootstrap css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function buildtree(&$result,$dropdown,$space='',$callback=null){ | |
$drop = false; | |
if(!is_array($dropdown) || count($dropdown) < 1 ){ return false; } | |
$i = 0; | |
$space .= $space; | |
while($i < count($dropdown)){ | |
$key = key($dropdown); | |
$item = ( is_numeric($key) ? $dropdown[$key] : $key ); | |
$childexist = !empty($dropdown[$item]) && is_array($dropdown[$item]); | |
if(is_callable($callback)){ | |
$result .= $callback($item,$childexist,$space); | |
} | |
if($childexist){//exist child array | |
$result .= '<div class="panel list-sub"> | |
<div class="panel-body"> | |
<div class="list-group">'; | |
} | |
if(is_array($dropdown[$key])){ | |
buildtree($result,$dropdown[$key],$space,$callback); | |
} | |
if($childexist){//exist child array | |
$result .= '</div> | |
</div> | |
</div>'; | |
} | |
next($dropdown); | |
$i++; | |
} | |
} | |
/*$dropdowns = array( | |
'category' => array( | |
'men'=>array('departments','designers','surf by price','surf by size'=>array('one','two'=>array('one','two','three','four'),'three','four')), | |
'women'=>array('departments','designers','surf by price','surf by size'), | |
'handbags'=>array('styles','designers','surf by price','surf by material') | |
), | |
'condition' => array(), | |
'size' => array(), | |
'Brand' => array(), | |
'Pricing' => array() | |
);*/ | |
$result = ''; | |
$space = ' '; | |
buildtree($result,$dropdowns,$space,function($item,$childexist,$space){ | |
return '<a href="#" class="list-group-item"><span>'.$space.$item.'</span>'. | |
( $childexist ? '<span class="glyphicon glyphicon-menu-right mg-icon pull-right"></span>' : '' ). | |
'</a>'; | |
}); | |
?> | |
<div class="row"> | |
<div class="col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1"> | |
<div class="panel panel-default"> | |
<div class="panel-body"> | |
<div class="slide-container"> | |
<div class="list-group" id="mg-multisidetabs"> | |
<?php echo $result; ?> | |
</div><!-- ./ end list-group --> | |
</div><!-- ./ end slide-container --> | |
</div><!-- ./ end panel-body --> | |
</div><!-- ./ end panel panel-default--> | |
</div><!-- ./ endcol-lg-6 col-lg-offset-3 --> | |
</div><!-- ./ end row --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment