You can create a hierarchy like this using references.
private function generateStructureArray($file) {
//split the file into paths
$splitData = explode('/', $file);
//pop off the filename
$fileName = array_pop($splitData);
//create a temp reference to the hierarchy. Need a temp var
//because this will get overwritten again and again.
$tmp = &$this->hierarchy;
//loop over the folders in splitData
foreach($splitData as $folder){
//check if the folder doesn't already exists
if(!isset($tmp[$folder])){
//folder doesn't exist so set the folder to a new array
$tmp[$folder] = array();
}
//re-set tmp to a reference of the folder so we can assign children
$tmp = &$tmp[$folder];
}
//now we have the folder structure, but no file
//if file is not empty, add it to the last folder
if(!empty($fileName)){
$tmp[] = $fileName;
}
}
Example: http://codepad.viper-7.com/laXTVS