Jump to content
Sign in to follow this  
Ustag

sorting arrays

Recommended Posts

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.

Edited by Ustag

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×