- usort: documentation ( source)
- rand: documentation ( source)
<?php
class Job
{
public function isEarlierThan(Job $other)
{
return rand(0, 10) < 5;
}
}
$jobs = array(new Job(), new Job(), new Job());
return rand(0, 10) < 5;
usort($jobs, function($j1, $j2) {
return $j1->isEarlierThan($j2) ? -1 : 1;
});