3v4l.org

run code in 500+ PHP versions simultaneously
<?php trait Test { function init(){ $req = $this->getRequest(); $topics = $req['topics']; usort($topics, function($first, $next) { if(is_null($first['expiryDate'])) return 1; if(is_null($next['expiryDate'])) return -1; // otherwise ascending return $first['expiryDate'] <=> $next['expiryDate']; }); $req['topics'] = $topics; } } class Collection implements ArrayAccess { private $container = []; public function offsetSet($offset, $value):void { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset):bool { return isset($this->container[$offset]); } public function offsetUnset($offset):void{ unset($this->container[$offset]); } public function offsetGet($offset):mixed { return isset($this->container[$offset]) ? $this->container[$offset] : null; } } class SchedulerRepository { use Test; protected Collection $request; /** * @return Collection */ public function getRequest(): Collection { return $this->request; } public function bootstrap($data) { $this->request = $data; $this->init(); } } $data = new Collection; $data['topics'] = [ ['expiryDate' => 9], ['expiryDate' => 6], ['expiryDate' => 7], ]; $s = (new SchedulerRepository); $s->bootstrap($data); var_dump($s);

preferences:
89.38 ms | 1170 KiB | 5 Q