3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iterator = new ArrayIterator([new Test(10), new Test(1), new Test(5)]); $iterator->uasort( function ($first, $second) { return $first->getSortOrder() < $second->getSortOrder() ? -1 : 1; } ); $collection = new ArrayCollection(iterator_to_array($iterator)); var_dump($collection->getValues()); die; class Test { private $orderNr; function __construct($orderNr) { $this->orderNr = $orderNr; } public function getSortOrder() { return $this->orderNr; } }

preferences:
47.5 ms | 402 KiB | 5 Q