[eluser]nikefido[/eluser]
hey all - just wanted to let you all in on my solution, and my last issue to conquer with it.
So I read my venerable old "PHP5 Advanced" book (Visual quickpro guide) about array sorting and came up with my hacked version of directory_helper. Keep in mind I use this function to see directory structure for users of a file management project I am developing.
Here is my version:
Code:
if (! function_exists('directory_map'))
{
function directory_map($source_dir, $top_level_only = FALSE)
{
if ($fp = @opendir($source_dir))
{
$filedata = array();
while (FALSE !== ($file = readdir($fp)))
{
if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)
{
$temp_array = array();
$temp_array = directory_map($source_dir.$file."/");
$filedata[$source_dir.$file] = $temp_array; //$k => directory path; $v => directory files && sub-directories
uksort($filedata[$source_dir.$file], 'mysort');//this will always be an array, so sort it here!
}
elseif (substr($file, 0, 1) != ".")
{
$filedata[$source_dir.$file] = $source_dir.$file; //$k => file path; $v => file path
}
}
return $filedata;
}
}
}
function mysort($x, $y) {
return strcasecmp($x, $y);
}
Notice that I use the uksort function within the helper in order to get around doing another recursive function to sort the arrays after the directory_helper function.
My final hump was that I needed to do the uksort function one last time in order to order the very top tier. This worked when I just do (in testing within the directory_helper.php file)
Code:
$myarray = directory_map('path/to/folder/');
uksort($myarray, 'mysort');
print_r($myarray);
However, in "production", I had to do this("this" will seem obvious but I had to go through a hoop or two on my own to get to it

):
Code:
$this->load->helper('directory');
$directory = directory_map('path/to/folder/');
uksort($directory, 'mysort'); //final sort to top tier of items - didn't have to re=declare a sorting function since it is included with my hacked directory_helper