I have an array which includes all of my directories in my homedir. I am running a foreach loop where I need to output " </ul>
" for my dropdown menu. I need output the closing tags at the end of the last subdirectory of the parent directory or where there are line breaks. (I grouped my array by spaces below.)
I have no idea how to logically approach this problem. I figure maybe a recursive function would help but I do not know where to begin.
Array ( [0] => Array ( [0] => test_php [1] => test_php )
[1] => Array ( [0] => bootstrap-336-dist [1] => bootstrap-3.3.6-dist )
[2] => Array ( [0] => .css [1] => bootstrap-3.3.6-dist/css )
[3] => Array ( [0] => .fonts [1] => bootstrap-3.3.6-dist/fonts )
[4] => Array ( [0] => .js [1] => bootstrap-3.3.6-dist/js )
[5] => Array ( [0] => dynasty_loop [1] => dynasty_loop )
[6] => Array ( [0] => .C1_00626E58960C [1] => dynasty_loop/C1_00626E58960C )
[7] => Array ( [0] => ..snap [1] => dynasty_loop/C1_00626E58960C/snap )
[8] => Array ( [0] => .C1_00626E5894EF [1] => dynasty_loop/C1_00626E5894EF )
[9] => Array ( [0] => ..snap [1] => dynasty_loop/C1_00626E5894EF/snap )
[10] => Array ( [0] => nvr_snapshots [1] => nvr_snapshots )
[11] => Array ( [0] => .snap [1] => nvr_snapshots/snap )
[12] => Array ( [0] => test_php2 [1] => test_php2 ) )
I figured it out. Here is my answer if anyone is looking for something similar. My foreach loop syntax is not closed off so beware of that.
foreach($_SESSION['menulite'] as $key => $url) {
$url_raw = $url;
$key_raw = $key;
$url[0]=trim($url[0],'.');
$nextmenuitem = $_SESSION['menulite'][$key + 1];
//if (substr($nextmenuitem[0],0,1)=='.') {
$padding_left='';
$padding_left = (substr_count($nextmenuitem[0], '.', 0, strpos($nextmenuitem[0], trim($nextmenuitem[0], '.'))) -1);
if ( strpos( $url_raw[0],'.' ) !== 0 && strpos( $nextmenuitem[0],'.' ) !== 0 ) {
$div1 = "<li role=\"presentation\">" ;
$div2 = "</li>";
}
if ( strpos( $url_raw[0],'.' ) !== 0 && strpos( $nextmenuitem[0],'.' ) === 0 ) {
$div1 = "<li role=\"presentation\" $class1> <a$dropdown> $url_raw[0] $caret </a> <ul class=\"dropdown-menu\">" ;
$div2 = null;
}
if ( strpos( $url_raw[0],'.' ) === 0 && strpos( $nextmenuitem[0],'.' ) === 0 ) {
$div1 = "<li>" ;
$div2 = "</li>";
}
if ( strpos( $url_raw[0],'.' ) === 0 && strpos( $nextmenuitem[0],'.' ) !== 0 ) {
$div1 = "<li>" ;
$div2 = "</li>";
//echo "</ul>";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.