I am sorting an array using values alphabetically, the array is as below:
Array (
[0] => test This
[1] => This test
[2] => again this test
[3] => test again this
[4] => this test again
[5] => Dallas University Texas
[6] => Texas Dallas University
[7] => University Texas Dallas
[8] => dallas University Texas
[9] => Texas dallas University
[10] => University Texas dallas
[11] => Johnson Johnson
[12] => Johnson Johnson
)
the expected output when i sort should be as below:
again this test
dallas University Texas
Dallas University Texas
Johnson Johnson
test again this
test This
this test again
Texas dallas University
Texas Dallas University
This test
University Texas dallas
University Texas Dallas
my code is below:
the comparator
function compareValues($a,$b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
function transform($input){
return usort($input,array($input,"compareValues"));
}
print_r($transform($input));
My current output cannot alphabetize the all values and is not case sensitive, it can only produce partially ordered array. It should be the comparator function that has some fault.