- var_dump: documentation ( source)
- iterator_to_array: documentation ( source)
<?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;
}
}