AuntieSocial Posted April 18, 2007 Share Posted April 18, 2007 Been cracking my head on this for a bit. help sorely needed! (I'm a php novice,please excuse ) I have a multi-dimensional representing a file in a particular directory and sub directories. ex: I have dir1/dir2/dir3/3.jpg dir1/dir2/dir3/dir4/4.jpg The array is set up as follows: Array ( [0] => Array ( [0] => dir1 [1] => dir2 [2] => dir3 [3] => 3.jpg ) [1] => Array ( [0] => dir1 [1] => dir2 [2] => dir3 [3] => dir4 [4] => 4.jpg ) ) what I'm looking to do is to create an array from the above array to represent the directory structure, something like this: (or perhaps using only integer as keys?) Array ( [dir1] => Array ( [dir2] => Array ( [dir3] => Array ( [0] => 3.jpg [dir4] => Array ( [0] => 4.jpg ) ) ) ) ) how can this be achieved? Would greatly appreciate help! clueless Link to comment https://forums.phpfreaks.com/topic/47636-help-howto-reorganize-a-multi-dimensional-array/ Share on other sites More sharing options...
AV1611 Posted April 18, 2007 Share Posted April 18, 2007 Please don't take this the wrong way, but WHY??? Link to comment https://forums.phpfreaks.com/topic/47636-help-howto-reorganize-a-multi-dimensional-array/#findComment-232626 Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 It can be done, I am quite interested why also like AV pointed out. This is how I would organize the array $dirArray = array("dir1" => array(), "dir2" => array(), "dir3" => array("3.jpg"), "dir4" => array("4.jpg")); Simple and easy. If you MUST have it the way you have shown above look into recursion http://en.wikipedia.org/wiki/Recursion Link to comment https://forums.phpfreaks.com/topic/47636-help-howto-reorganize-a-multi-dimensional-array/#findComment-232638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.