In the PHP manual, the usort syntax is boolusort (array & amp; array, callback $ cmp_function) in the next example, in the custom functions, $ str1 and $ str2 receive the values in the array in the order in which they are sorted by 1,-, and 0? Thank you! Example: (separate an array by parity and then sort it by size) $ str2) return-1; elsereturn1;} if ($ str1 % 20) return1; if ($ str2 % 20) how php functions work
In the PHP manual, the usort syntax is bool usort (array & array, callback $ cmp_function)
In the following example, in the user-defined functions, $ str1 and $ str2 receive the values in the array in the order in which they are sorted by 1,-1, 0? Thank you!
Example: (separate an array by parity and sort it by size)
If ($ str1 % 2 = 0) & ($ str2 = 0 )){
If ($ str1> $ str2) return-1; else return 1 ;}
If ($ str1 % 2 = 0) return 1;
If ($ str2 % 2 = 0) return-1;
Return ($ str2> $ str1 )? 1:-1 ;}$ scores = array (64,78, 51,86, 97,60, 87,91, 100,17, 62); usort ($ scores, 'compare ');
Print_r ($ scores );
?>
This is the output result:
Array ([0] => 97 [1] => 91 [2] => 87 [3] => 51 [4] => 17 [5] => 86 [6] => 64 [7] => 78 [8] => 100 [9] => 60 [10] => 62)