简体   繁体   English

在多维数组$ value中搜索字符串

[英]Search string in Multidimensional Array $value

I have an array which includes all of my directories in my homedir. 我有一个数组,其中包含我的homedir中的所有目录。 I am running a foreach loop where I need to output " </ul> " for my dropdown menu. 我正在运行一个foreach循环,我需要在下拉菜单中输出“ </ul> ”。 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循环语法尚未关闭,请当心。

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>";


                    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM