php - Get complete file path from an array -
i have array (which comes specific function : list , filter files of directory on extension) :
array (     [dir_test] = array         (             [dir_client] = array                 (                     [0] = index.html                 )              [0] = index.html         ) ) and like. note : directory have way more subdirs.
array (     [0] = dir_test/dir_client/index.html     [1] = dir_test/index.html ) thx ;)
assuming input data looks this:
$arr = array(     'dir_test' => array (         'dir_client' => array (             0 => 'index.html'         ),          0 => 'index.html'     ) ); the easiest solution recursive one, like:
function add_dir($dir) {     global $dirs;      $dirs[] = $dir; }  // pathsofar should end in '/' function process_dir($dirarray, $pathsofar) {     foreach ($dirarray $key => $value) {         if (is_array($value)) {             process_dir($value, $pathsofar . $key . '/');         } else {             add_dir($pathsofar . $value);         }     } }  process_dir($arr, '');  print_r($dirs); running it:
$ php arr2.php array (     [0] => dir_test/dir_client/index.html     [1] => dir_test/index.html ) 
Comments
Post a Comment