I'm quite new to programming and I've been trying to get something, that seemed rather simple, done but it's taking me way too long and I do not have the feeling that I'm getting anywhere close...
I'm trying to format an array that looks like this:
Array (
[1] = "index.php"
[2] = "page.php"
[3] = "sub/subpage.php"
[4] = "sub/subpage2.php"
[5] = "sub/subsub/subsubpage.php"
[6] = "sub/subsub/subsubpage2.php"
[7] = "sub2/sub2page.php"
)
Into an array that looks like this:
Array (
[/] => Array (
[0] => "index.php"
[1] => "page.php"
)
[/sub] => Array (
[0] => "subpage.php"
[1] => "subpage2.php"
[/subsub] => Array (
[0] => "subsubpage.php"
[1] => "subsubpage2.php"
)
)
[/sub2] => Array (
[0] => "sub2page.php"
)
)
I'm hoping this example shows what I'm trying to do... Which is basically reformatting my original (simple) array into an array that I can use to create some kind of navigation in HTML (using nested ul's)
Thanks in advance!
EDIT:
I've tried this to create the multidimensional array...
$parts = explode('/', trim($page["parent"], "/"));
while ( !empty($parts) ) {
$pageList[array_pop($parts)] = $page["filename"];
}
// $page = array("filename" => "example.php", "parent" => "sub/sub/")