Jump to content

ordering data


dcole.ath.cx
 Share

Recommended Posts

what script would I use to orgainize data from smallest number to largest numberlike:7 -- DCole3 -- SFB5 -- Justsomeguy1 -- Bob9 -- fredinto1 -- Bob3 -- SFB5 -- Justsomeguy7 -- DCole9 -- fredeach line can be a variable and each number can be var[0]

Link to comment
Share on other sites

If all of the numbers are unique, the easiest thing to do is create an array of everything and sort the array using ksort.

<?php$list = array();$list[7] = "DCole";$list[3] = "SFB";//etcksort($list);?>

If the numbers are not unique, you will want to create a multidimensional array and use usort.

<?php$list = array();$item['id'] = 7;$item['text'] = "DCole";$list[] = $item;$item['id'] = 3;$item['text'] = "SFB";$list[] = $item;usort($list, cmp_function);function cmp_function($a, $b) {   if ($a['id'] == $b['id']) {       return 0;   }   return ($a['id'] < $b['id']) ? -1 : 1;}?>

Link to comment
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
 Share

×
×
  • Create New...