PHP Usort Sorting issues
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 $a and $b are all letters, so return ($a > $b)? -1:1; The comparison between this, I do not understand the letters between if than the size
2. $a $b what they all represent
------Solution--------------------
Like bubble sort.
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");p Rint_r ($arr);