Well, after a few hours of staring at the functions I last posted, reading up on different functions and trying out different things I was not able to figure much out.
But I was able to come up with the following, which does what I want:
PHP Code:
<?php
function tag($a, $b) {return (substr($a,-9) > substr($b,-9));}
$a=array('that--DIRECTORY','next--DIRECTORY','big','this','dad--DIRECTORY','fruit','apple--DIRECTORY','aaaaaaaaaaaa');
usort($a,'tag');
foreach ($a as $k => $v)
{
$pos = strpos($v, '--DIRECTORY');
if ($pos !== false)
{
$pos=$k;
break;
}
}
foreach ($a as $k => $v)
{
$pos1 = strpos($v, '--DIRECTORY');
if ($pos1 !== false)
{
$pos2++;
}
}
$begin=array_splice($a,$pos,$pos2);
natcasesort($begin);
$end=$a;
natcasesort($end);
$a=array_merge($begin,$end);
if ($pos===false) natcasesort($a);
print_r($a);
?>
produces
Code:
Array ( [0] => apple--DIRECTORY [1] => dad--DIRECTORY [2] => next--DIRECTORY [3] => that
--DIRECTORY [4] => aaaaaaaaaaaa [5] => big [6] => fruit [7] => this )
I am sure this can be cleaned up and made more efficient, but it works.
Bookmarks