I got directory array below.
I will make a file search in this array. For example path.php , survey.php... If file is found , how should a construct the path.
for path.php
I want function to return '/survey/config/path.php'
Array
(
[survey] => Array
(
[config] => Array
(
[0] => path.php
[1] => routes.php
)
[controllers] => Array
(
[0] => admin.php
[1] => giris.php
)
[models] => Array
(
开发者_开发百科 [0] => giris.php
)
[views] => Array
(
[0] => admin_form.php
[1] => widget.php
[2] => yeni_form.php
)
[widgets] => Array
(
[0] => survey.php
)
)
)
function find_file_path($dir_structure, $filename) {
foreach($dir_structure as $dir => $subpath) {
if(is_array($subpath)) {
$sub_found = find_file_path($subpath, $filename);
if($sub_found) {
return "/" . $dir . $sub_found;
}
} else {
if($subpath === $filename) {
return "/$filename";
}
}
}
return FALSE;
}
精彩评论