Directory tree as an associative array? - 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: Directory tree as an associative array? (/showthread.php?tid=15984) |
Directory tree as an associative array? - El Forum - 02-21-2009 [eluser]kyleect[/eluser] Consider the following: Quote:/ What I'd like to do is access this structure as an associative array: Code: echo $array['dir1']['file1']; I can figure out how to write the file contents from the files, the real issue I'm having is finding a native or non native php function for listing directories as an associative array. Directory tree as an associative array? - El Forum - 02-21-2009 [eluser]TheFuzzy0ne[/eluser] I'm not sure if it's a wise idea. If you were to call this function in a directory that contained many levels of directories, you could end up using a very large amount of memory, or possible even exhausting it completely. Calling a function recursively like that on a potentially unlimited result set could be a real painus in the anus. Can I ask what you're hoping to achieve, as there's probably a much better solution? Directory tree as an associative array? - El Forum - 02-21-2009 [eluser]TheFuzzy0ne[/eluser] Here's a function that will allow limited recursion. Code: # Original PHP code by Chirp Internet: www.chirp.com.au Directory tree as an associative array? - El Forum - 02-21-2009 [eluser]kyleect[/eluser] Basically, its going to scan the directory that contains my style sheets and directories that contain style sheets. They are then compiled in to a single css file however different style sheets are handled differently based what directories they are in. Directory tree as an associative array? - El Forum - 02-21-2009 [eluser]TheFuzzy0ne[/eluser] I'm sure you have your reasons, but it sounds very complex to me. I use a little asset management library I created which allows me to configure default styles that will show on every page, and add more styles, script or meta data from within the controller or view with a function call. Would you be interested in that? There are some very good asset management libraries out there, but all the ones I found seemed like overkill for what I needed. |