CodeIgniter Forums
Using function directory_map - 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: Using function directory_map (/showthread.php?tid=10145)

Pages: 1 2


Using function directory_map - El Forum - 07-21-2008

[eluser]Colin Williams[/eluser]
Just note that my use of the static variable $paths is probably not the most elegant solution (try calling the function twice... yeah). I would suggest rethinking this before you use it heavily!

==== UPDATE =============================================================

Okay.. here's a better function. I had nothing else to do. It is sad, really:

Code:
function directory_map_paths($wp = '', $map = array())
{
   $paths = array();
   if (!is_array($map) or !count($map))
   {
      if ($wp)
      {
         $map = directory_map($wp);
         $wp = '';
      }
      else
      {
         show_error('No map or working path given to remap.');
      }
   }
   if (count($map))
   {
      foreach ($map as $k => $v)
      {
         if (is_array($v))
         {
            $paths = array_merge($paths, directory_map_paths($wp . ($wp ? '/' : '') . $k, $v)); // Recurse
         }
         else
         {
            $paths[] = $wp . ($wp ? '/' : '') . $v;
         }
      }
   }
   return $paths;
}