Peuplarchie wrote:What I'm trying to do here is to echo only the ones with dir as "dir" as 4th key.
Actually, the key is 'kind' 🙂
ksort($mod_array);
return $mod_array;
$key = array_search('dir', $mod_array);
echo '<pre>';
echo $key;
echo '</pre>';
}
Well, the ksort() won't achieve anything, because it's sorting the keys of $mod_array - which are all numeric.
And everything after the [font=monospace]return[/font] will of course be missed because it's after the return. So I'll assume that it's an example of how the results of the function will be used, that the '}' is misplaced, and that there is a "$mod_array = recur_dir('Art/');" line somewhere.
Your array_search will not find anything in $mod_array because none of its elements is the string "dir". The elements of the elements of $mod_array might equal that string.
$mod_array = recur_dir('Art/');
You want to find all the elements in $mod_array that contain an element with a value of 'dir'. (I say "all" even though array_search would only return one, but if you have all of them you're free to pick whichever one you want).
$dirs = array()
foreach($mod_array as $entry)
{
if($entry['kind']=='dir')
$dirs[] = $entry;
}
print_r($dirs);
You could, if you wanted to be witty, put that test in a function and use it as a filter.
function is_a_directory($entry)
{
return $entry['kind']=='dir';
}
$dirs = array_filter($mod_array, 'is_a_directory');
All of which is assuming you might want the files as well for something. Otherwise, as sneakyimp suggests, if you only want directories, don't include non-directories in your results.