I need a function in php to sort a list of words according to an arbitrary ordering.
Any words in the list not in my predefined order should be sorted alphabetically at the end of the list.
Below is my first attempt, it is neither elegant or efficient. Can you suggest a better way to acheive this?
Thanks
public static function sortWords(&$inputArray){
$order=array("Banana","Orange", "Apple", "Kiwi");
sort($inputArray);
for($i=0;$i<count($inputArray));$i++){
$ac = $inputArray[$i];
$position = array_search($ac,$order);
if($position !== false && $i != $position){
$temp=$inputArray[$position];
$inputArray[$position]=$inputArray[$i];
$inputArray[$i]=$temp;
}
}
}