Sorting an array of classes
Posted: Thu Apr 08, 2004 12:08 pm
Hi there!
I have a class:
Now, during the parsing of my file, I create an arry of this class in a loop thats like so:
Now, what I would like to do is SORT this $pl array by ->kills How the HECK would I do something like this? I have tried everything under the sun 
Thanks
I have a class:
Code: Select all
class Player
{
var $name;
var $kills = 0;
var $deaths = 0;
var $rank = 0;
var $weapon = array("THOMPSON"=>0,"MP40"=>0,""=>0,"DYNAMITE"=>0,"GRENADE_LAUNCHER"=>0,
"BROWNING"=>0,"MACHINEGUN"=>0,"FLAMETHROWER"=>0,"PANZERFAUST"=>0,
"FG42"=>0,"FG42SCOPE"=>0,"COLT"=>0,"LUGER"=>0,"LANDMINE"=>0,"ARTY"=>0,
"MORTAR"=>0,"M7"=>0,"CARBINE"=>0,"AIRSTRIKE"=>0,"STEN"=>0,"K43"=>0,
"AKIMBO_COLT"=>0,"AKIMBO_LUGER"=>0,"MG42"=>0,"MOBILE_MG42"=>0,
"KAR98"=>0,"KNIFE"=>0,"GPG40"=>0,"SATCHEL"=>0,"CRUSH_CONSTRUCTION"=>0,
"GARAND"=>0,"GARAND_SCOPE"=>0,"SILENCER"=>0,"K43_SCOPE"=>0,
"AKIMBO_SILENCEDLUGER"=>0,"SILENCED_COLT"=>0,"AKIMBO_SILENCEDCOLT"=>0);
function dominant_weapon()
{
$res = 0;
foreach($this->weapon as $tot)
{
if($tot > $res)
{
$res = $tot;
}
}
return array_search($res,$this->weapon);
}
}Code: Select all
$plї$player_count] = new Player;
$plї$player_count]->name = $matchї1];
$plї$player_count]->kills += 1;
$player_count += 1;Thanks