Ustag Posted April 10, 2012 Share Posted April 10, 2012 Hi, I am generating a bunch of arrays but I would like to change the order of these. This is my code now: $players_killed['time'] = strtotime($time);$players_killed['name'] = ': '.$player;arsort($players_killed, SORT_NUMERIC);echo var_dump($players_killed) .'<br>'; And this is the output: array(2) { ["time"]=> int(1334027580) ["name"]=> string(106) ": Brbasher" }array(2) { ["time"]=> int(1334029860) ["name"]=> string(102) ": Dynext" }array(2) { ["time"]=> int(1334029260) ["name"]=> string(110) ": Kronigrass" }array(2) { ["time"]=> int(1334036580) ["name"]=> string(108) ": Poliminia" } How can I make them order by the time value? My attempt with arsort($players_killed, SORT_NUMERIC); sure failed. Link to comment Share on other sites More sharing options...
Err Posted April 10, 2012 Share Posted April 10, 2012 It seems like that you're creating a new array every time instead of having everything in one array. Sorting will only work if you have all you data within an array. Link to comment Share on other sites More sharing options...
Ingolme Posted April 10, 2012 Share Posted April 10, 2012 You can sort multidimensional arrays, but you need to use a custom sorting function. This page shows how to sort a multidimensional array:http://es.php.net/manual/en/function.usort.php Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.