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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...