How can I sort this array of version values?
$available_databases = array(
"4.0.1",
"trunk",
"branch",
"4.1.0",
"4.0.3"
);
so that the result is
4.1.0
4.0.3
4.0.1
branch
trunk
You could use PHP's built-in array operations and such to do a lot of the heavy lifting for you, thus cutting out a lot of the apparent complexity:
$names = preg_grep('/^\D/', $arr);
$versions = preg_grep('/^\d/', $arr);
usort($versions, 'version_compare');
usort($names, 'strcasecmp');
$sorted = array_merge(array_reverse($versions), $names);