Trying to make multilevel dynamic menu in PHP using RecursiveIteratorIterator
<p>I am trying to code a multilevel page menu navigation but not working correcly and i doubt that it is something to do with the line RecursiveIteratorIterator, any help would be appreciated .I was thinking in the solution that way but maybe I went far. Thanks for the help.
Here is my code :</p>

<pre><code>&lt;ul id="nav"&gt;
       &lt;?php
 //searchWebsitePagesPath("blog.php");
 ?&gt;
        &lt;li&gt;&lt;a href="&lt;?php  echo searchWebsitePagesPath('index.php'); ?&gt;"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;!--        &lt;li&gt;&lt;a href="index.php" id="here"&gt;Home&lt;/a&gt;&lt;/li&gt;      --&gt;
        &lt;li&gt;&lt;a href="&lt;?php  echo searchWebsitePagesPath('blog.php'); ?&gt;"&gt;Journal&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="&lt;?php  echo searchWebsitePagesPath('gallery.php'); ?&gt;"&gt;Gallery&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="&lt;?php  echo searchWebsitePagesPath('files_upload.php'); ?&gt;"&gt;Upload&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="&lt;?php  echo searchWebsitePagesPath('contact.php'); ?&gt;"&gt;contact&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="&lt;?php  echo searchWebsitePagesPath('register.php'); ?&gt;"&gt;Register&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;?php

    function searchWebsitePagesPath($pageName){
        // echo ("$pageName");
        //    $files = "";
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.'));

        $my_path="";
        $myArray="";
        $pathReplace="";
        $finalPathReplace="";
        foreach ($files as $file) {

            if($file-&gt;getFilename() === $pageName ){
                $pathReplace=str_replace (str_replace('/','\\',$_SERVER['DOCUMENT_ROOT']),'',$file-&gt;getRealPath());
                $finalPathReplace = $pathReplace ;
                //           echo $finalPathReplace;
                $myArray=explode("\\",$pathReplace) ;
                $count= count($myArray);
                $reverted = new ArrayIterator(array_reverse($myArray));
                $server_path="" ;
                for($i=1;$i&lt;$count;$i=$i+1 ) {
                    $server_path =$server_path."../";
                }

                $my_path=$server_path.$reverted[$count-1];
            }

        }

        $my_path="\"$my_path\"" ;
        $files = "";
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("$my_path"));
        foreach ($files as $file) {

            if($file-&gt;getFilename() === $pageName ){
                $pathReplace=str_replace (str_replace('/','\\',$_SERVER['DOCUMENT_ROOT']),'',$file-&gt;getRealPath());
                $finalPathReplace ='/'.str_replace ('\\','/',$pathReplace)  ;
                return $finalPathReplace;
            }

        }

    }

    ?&gt;
</code></pre>
