I have a table/array. E.g. in Excel I can sort by column 1 asc, column 2 desc, column 3 asc, etc.
Can I do same in PHP? First with ["first_name"] ASC
, then ["last_name"] DESC
, ["player_id"] ASC
and ["user_id"] DESC
.
array(2) {
[0]=> array(6) {
[0]=> string(8) "John",
["first_name"]=> string(8) "John",
[1]=> int(7) "44",
["score"]=> int(7) "44",
[2]=> string(2) "7",
["player_id"]=> string(2) "7",
[3]=> string(2) "3",
["user_id"]=> string(2) "3"
},
[1]=> array(6) {
[0]=> string(5) "Sam",
["first_name"]=> string(5) "Sam",
[1]=> int(7) "55",
["score"]=> int(7) "55",
[2]=> string(2) "1",
["player_id"]=> string(2) "1",
[3]=> string(2) "6",
["user_id"]=> string(2) "61"
}
}
(The array is much longer and deeper in reality, this is just an example.)
Update:
function byPlayerID($player, $compare) {
if($player['player_id'] > $compare['player_id'])
return 1; // move up
else if($player['player_id'] < $compare['player_id'])
return -1; // move down
else
return 0; // do nothing
if($player['score'] > $compare['score'])
return 1; // move up
else if($player['score'] < $compare['score'])
return -1; // move down
else
return 0; // do nothing
}
Update 2: Never mind, I just needed to remove return 0;