Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array (
- Array[0] (
- "name" => "John",
- "score" => 4
- ),
- Array[1] (
- "name" => "James",
- "score" => 2
- ),
- Array[2] (
- "name" => "Mary",
- "score" => 3
- )
- etc
- )
- <?php
- function usort_callback($a, $b)
- {
- if ( $a['score'] == $b['score'] )
- return 0;
- return ( $a['score'] < $b['score'] ) ? -1 : 1;
- }
- usort($array, 'usort_callback');
- function cmp($a, $b)
- {
- if ($a["score"] == $b["score"]) {
- return 0;
- }
- return ($a["score"] < $b["score"]) ? -1 : 1;
- }
- usort($a, "cmp");
Add Comment
Please, Sign In to add comment