CodeIgniter Forums
Array troubles - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Array troubles (/showthread.php?tid=7365)



Array troubles - El Forum - 04-05-2008

[eluser]Jamie Rumbelow[/eluser]
I've got a huge annoyance, i'm using the directory_map function in the directory helper to get an array of files, but I dont know what to do next. I'm trying to just list the file names, but I dont have anything to reference to in the index.

I've tried a foreach function, with an incrementing variable, and a for loop, but neither worked.


Array troubles - El Forum - 04-05-2008

[eluser]Seppo[/eluser]
I don't understand the problem... The only thing you want are the files? In that case you could use "get_filenames" function, in the file helper, instead... Equally, the usage is simple
Code:
$this->load->helper('directory');
        $map = directory_map(APPPATH);

        foreach ($map as $k => $v)
        {
            if (is_array($v))
            {
                echo 'Directory: ' . $k;
                // in $v we have another array with all the files, recursively.
            } else {
                echo 'File: ' . $v;
            }
            echo '<br />';
        }