3v4l.org

run code in 300+ PHP versions simultaneously
<?php class RouteCollection implements \IteratorAggregate, \Countable { /** * @var Route[] */ public $routes = array(); /** * Gets the current RouteCollection as an Iterator that includes all routes. * * It implements \IteratorAggregate. * * @see all() * * @return \ArrayIterator An \ArrayIterator object for iterating over routes */ public function getIterator() { return new \ArrayIterator($this->routes); } } $c = new RouteCollection(); $o = new stdClass; $o->prio = 1; $c->routes[] = $o; $o = new stdClass; $o->prio = 3; $c->routes[] = $o; $c->getIterator()->uasort(function($a, $b) { if ($a->prio == $b->prio ) { return 0; } return $a->prio > $b->prio ? 1 : -1; } ); var_dump($c->routes);

preferences:
43.58 ms | 402 KiB | 5 Q