I'm getting in a bit of a pickle with loops in php.
I'm using this code to generate a dynamic lists from .php pages in 3 sub-folders at my website root. This list will become a menu (once I've got it working).
The output is this example here: http://www.jemcon.org/process_script.../menu_test.php
$rooturl = '/home/www/mywebsite.com/';
$subfolders_path = opendir($rooturl);
while (false !== ($folder = readdir($subfolders_path)) )
if( (is_dir($rooturl.$folder)) && (substr($folder,0,1) != '.') )
$folders = explode (' ', $folder);
foreach ($folders as $sub_folder)
$dh = opendir($rooturl.$sub_folder);
echo '<ul id="'.$sub_folder.'" class="menu">';
while (false !== ($file = readdir($dh)) )
if (strpos($file, '.php',1)) // only include files with .php extension
if ( $file!='.' && $file!='..' )
$file_array = $file;
foreach ($file_array as $value)
echo '<li class="menu">'.$value.'</li>';
echo '</ul><br style="clear:both"/>';
As you can see, the script is repeating the php files from previously read sub-folders and including them in the following lists - see how the first list just displays colours from the "colour" folder but the second list then continues to display the previously read colours and adds them to the list for "animals", while the third list adds both to the last "drinks" list.
All I want is the script to generate this output (mocked-up a static HTML file as an example): http://www.jemcon.org/process_script...menu_test2.php
I know it's the looping which is off but I'm not sure how to fix it.
Can somebody help me please?