This is driving me crazy... can't seem to get the key of the arrays that are set initially? <? $fileArray = array("Directory" => array(), "File" => array()); if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(is_dir($file)) { $fileArray["Directory"][] = $file; } else { $fileArray["File"][] = $file; } } } closedir($handle); } rsort($fileArray); foreach ($fileArray as $fileType) { ?> <h2><?=print(array_keys($fileArray))?></h2> <? foreach($fileType as $file) { ?> <a href="/<?=$file?>"><?=$file?></a><br /> <? } } ?> PHP:
That gives 0 and 1 so I guess that's kind of right, just need the text value of they key which I can't seem to get.
Can you add this line both before and after the rsort function echo '<pre>'.print_r($fileArray, true).'</pre>'; PHP: And show the output here for the two arrays
Array ( [0] => Array ( [0] => index.php [1] => sqlite_test.php [2] => apache_pb.png [3] => phpinfo.php [4] => index.htm.old ) [1] => Array ( [0] => Test ) ) Code (markup):
This is after the rsort I take it. Change rsort to arsort and see if that fixes it. rsort doesn't maintain the keys by default (see the manual - http://www.php.net/rsort)
Excellent that sorted it out, don't really use arrays too much so I just used the first sort I found.