You must use the usort function.
$isVersion = function($a) { return is_numeric( str_replace('.', '', $a) ); }; $sortFunction = function($a, $b) use($isVersion) { if( $isVersion($a) && $isVersion($b) ) { return version_compare($b, $a); // reversed for your proper ordering } elseif( $isVersion($a) ) { return -1; } elseif( $isVersion($b) ) { return 1; } else { return strcasecmp($a, $b); } }; usort($yourArray, $sortFunction);
The usort function allows you to use your own callback for comparison. I wrote one for you with the logic that you wanted: if both comparable elements are versions, it uses version_compare to compare them with the changed parameters, since you want it in descending order. If the second comparable item is a string and the first is a version, the version is considered “lower” than the string, and vice versa. If both elements are strings, it uses the strcasecmp comparison strcasecmp to determine the correct ordering.
Example usage: codepad
source share