Using JFolder:
$tree = JFolder::listFolderTree('myfolder');
Lists the tree structure like this: (ignore and ignore2 are subfolders inside each folder b,n,v)
Array
(
[0] => Array
(
[id] => 1
[parent] => 0
[name] => b
[fullname] => myfolder/b
[relname] => myfolder/b
)
[1] => Array
(
[id] => 2
[parent] => 1
[name] => ignore
[fullname] => myfolder/ignore
[relname] => myfolder/ignore
)
[2] => Array
(
[id] => 3
[parent] => 1
[name] => ignore2
[fullname] => myfolder/ignore2
[relname] => myfolder/ignore2
)
[3] => Array
(
[id] => 4
[parent] => 0
[name] => n
[fullname] => myfolder/n
[relname] => myfolder/n
)
[4] => Array
(
[id] => 5
[parent] => 4
[name] => ignore
[fullname] => myfolder/ignore
[relname] => myfolder/ignore
)
[5] => Array
(
[id] => 6
[parent] => 4
[name] => ignore2
[fullname] => myfolder/ignore2
[relname] => myfolder/ignore2
)
[6] => Array
(
[id] => 7
[parent] => 0
[name] => v
[fullname] => myfolder/v
[relname] => myfolder/v
)
[7] => Array
(
[id] => 8
[parent] => 7
[name] => ignore
[fullname] => myfolder/ignore
[relname] => myfolder/ignore
)
[8] => Array
(
[id] => 9
[parent] => 7
[name] => ignore2
[fullname] => myfolder/ignore2
[relname] => myfolder/ignore2
)
)
So we can see the ordering of the folders: 0 has name "b" 1 has name "n" and 2 has name "v".
Now I want to order them in user defined order from the array:
$user_defined_array = [b,v,n];
So now the $tree ordering should 0 => b, 1 => v and 2 => n
and if the user changes the the array like [n,v,b]
then ordering should be like that.
For example if user defined array like [b,v,n]
the resulting array should look like this:
Array
(
[0] => Array
(
[id] => 1
[parent] => 0
[name] => b
[fullname] => myfolder/b
[relname] => myfolder/b
)
[1] => Array
(
[id] => 2
[parent] => 1
[name] => ignore
[fullname] => myfolder/ignore
[relname] => myfolder/ignore
)
[2] => Array
(
[id] => 3
[parent] => 1
[name] => ignore2
[fullname] => myfolder/ignore2
[relname] => myfolder/ignore2
)
[3] => Array
(
[id] => 4
[parent] => 0
[name] => v
[fullname] => myfolder/v
[relname] => myfolder/v
)
[4] => Array
(
[id] => 5
[parent] => 4
[name] => ignore
[fullname] => myfolder/ignore
[relname] => myfolder/ignore
)
[5] => Array
(
[id] => 6
[parent] => 4
[name] => ignore2
[fullname] => myfolder/ignore2
[relname] => myfolder/ignore2
)
[6] => Array
(
[id] => 7
[parent] => 0
[name] => n
[fullname] => myfolder/n
[relname] => myfolder/n
)
[7] => Array
(
[id] => 8
[parent] => 7
[name] => ignore
[fullname] => myfolder/ignore
[relname] => myfolder/ignore
)
[8] => Array
(
[id] => 9
[parent] => 7
[name] => ignore2
[fullname] => myfolder/ignore2
[relname] => myfolder/ignore2
)
)
I hope question is clear and I hope there is a way.