Jump to content

[SOLVED] Help sorting a multi dimensional array


SonicUK

Recommended Posts

Ok here's the array:

$DKP_table
{
[1]
    ['id'] = 1
    ['name'] = Treachery
    ['class'] = Warrior
    ['dkp'] = 50

[2]
    ['id'] = 2
    ['name'] = Bob
    ['class'] = Paladin
    ['dkp'] = 35

[3]
    ['id'] = 3
    ['name'] = Hadria
    ['class'] = Druid
    ['dkp'] = 60
}

foreach ($DKP_table as $value)
{
    print the table
}

 

What i need is for the it to be sorted by ['name'] , ['dkp'] or ['class']. Its not really essential just a nice feature. Can this be done?

Thanks. I had looked at that page briefly before but didnt really understand half of it.. when i looked again i found an example which did what i want:

 

$sort_arr = array();
foreach($DKP_table AS $uniqid => $row){
foreach($row AS $key=>$value){
	$sort_arr[$key][$uniqid] = $value;
}
}

array_multisort($sort_arr['dkp'], SORT_DESC, $DKP_table);

foreach ($DKP_table as $value)
{
    print the table
}

 

This is for a Guild website for world of warcraft btw, and this is my first projecting doing something more than me just muckin around. err the reason i didnt sort directly from sql is because the data is coming from 3 tables. 1 holds the list of players, another holds a list of awards, the 3rd is a linking table which has the id's of which players got which awards. Each table goes into an array, and then it calculates how much each player got in total.

 

Anyway, seems to work fine. I'll be making that code abit more flexable ofc to use on other things.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.