get_priority() == $b->get_priority()) { return 0; } return ($a->get_priority() < $b->get_priority()) ? -1 : 1; } # General Collection Class class collection { var $items; # $key should be a string # $value should be an actor function put($key,$value) { if (isset($this->items[$key])) { $this->items[$key][count($this->items[$key])] = $value; uasort($this->items[$key],"priority_sort"); } else { $this->items[$key] = array($value); } } # get will return an array of actors or false # You _MUST_ use php's iterator each() to access to elements in order # indexing them 0,1,...,n-1 will not work because sorting != re-indexing # There is a working example of this class at the bottom of this file... function get($key) { if (isset($this->items[$key])) { return $this->items[$key]; } else { return false; } } } # Example Code using class collection. # # $col = new collection(); # include("event_handler.class.php"); # # $one = new event_handler(); # $two = new event_handler(); # $thr = new event_handler(); # # $one->set_priority(1); # $two->set_priority(2); # $thr->set_priority(3); # # $one->set_name("one"); # $two->set_name("two"); # $thr->set_name("thr"); # # $col->put("event_name",$thr); # 3 # $col->put("event_name",$one); # 1 # $col->put("event_name",$two); # 2 # # $x = $col->get("event_name"); # while (list($key, $value) = each($x)) { # echo $x[$key]->get_priority(); # echo " "; # } # echo "\n"; ?>