3v4l.org

run code in 300+ PHP versions simultaneously
<?php $aO = new ArrayObject(); $aO['3'] = (object) ['sortKey'=>8, 'label'=>'three']; $aO['1'] = (object) ['sortKey'=>6, 'label'=>'one']; $aO['5'] = (object) ['sortKey'=>4, 'label'=>'five']; $output = applyOrder($aO, ['sortKey'=>'ASC']); var_dump($output); function applyOrder(array $resources, array $orderBy) { $results = $resources; foreach ($orderBy as $property => $order) { $sortable = []; foreach ($results as $key => $object) { $sortable[$key] = $object->$property; if (null === $sortable[$key]) { unset($sortable[$key]); } } if ('ASC' === $order) { asort($sortable); } elseif ('DESC' === $order) { arsort($sortable); } $results = []; foreach ($sortable as $key => $propertyValue) { $results[$key] = $resources[$key]; } } return $results; }
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: applyOrder(): Argument #1 ($resources) must be of type array, ArrayObject given, called in /in/0nrQE on line 9 and defined in /in/0nrQE:12 Stack trace: #0 /in/0nrQE(9): applyOrder(Object(ArrayObject), Array) #1 {main} thrown in /in/0nrQE on line 12
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
56.07 ms | 401 KiB | 8 Q