Echo & lt; pre & gt; functionmy_sort ($ a, $ B) & nbsp ;{& nbsp; & nbsp; if ($ a $ B) return0; var_dump ($ a); var_dump ($ B); echo & lt; br & gt; & nbsp; return ($ a & gt; $ B) php usort sorting problem
Echo'
';
Function my_sort ($ a, $ B)
{
If ($ a = $ B) return 0;
Var_dump ($ a); var_dump ($ B); echo'
';
Return ($ a> $ B )? -1: 1;
}
$ Arr = array ("Peter", "glenn", "Cleveland", "peter", "cleveland", "Glenn ");
Usort ($ arr, "my_sort ");
Print_r ($ arr );
1. I don't understand that $ a and $ B are both letters, so return ($ a> $ B )? -1: 1; I do not understand the ratio of the ratio between letters.
2. $ a $ B What do they represent?
------ Solution --------------------
For example, bubble sorting
PHP code
For ($ I = 0; $ I
$ Ar [$ j]) {swap ($ ar [$ I], $ ar [$ j]) ;}}
------ Solution --------------------
PHP code
$arr = array("Peter"=>array('a0'=>'a','a1'=>'3'),"glenn"=>array('b0'=>'a','b1'=>'1'),"Cleveland"=>array('c0'=>'a','c1'=>'2'));function my_sort($a, $b) { return strcasecmp(end($a), end($b));}uasort($arr, "my_sort");print_r ($arr);