3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $aO = new ArrayObject(); $aO['3'] = (object)['sortKey'=>8, 'label'=>'three']; $aO['1'] = (object)['sortKey'=>6, 'label'=>'one']; $aO['a'] = (object)['sortKey'=>4, 'label'=>'Letter A']; $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; }
based on 0nrQE
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Argument 1 passed to applyOrder() must be of the type array, object given, called in /in/FGvLB on line 9 and defined in /in/FGvLB:12 Stack trace: #0 /in/FGvLB(9): applyOrder(Object(ArrayObject), Array) #1 {main} thrown in /in/FGvLB on line 12
Process exited with code 255.
Output for 5.4.12 - 5.6.28
Catchable fatal error: Argument 1 passed to applyOrder() must be of the type array, object given, called in /in/FGvLB on line 9 and defined in /in/FGvLB on line 12
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/FGvLB on line 5
Process exited with code 255.