3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $menu = array( array(1,3,'Wurm 1.1', 2, 10), array(2,6,'Vogel 2.1', 2, 30), array(3,0,'Tiger 1', 1, 10), array(4,6,'Hund 2.2', 2, 40), array(5,3,'Katze 1.2', 2, 11), array(6,0,'Pferd 2', 1, 20), array(7,1,'Baer 1.1.1', 3, 0), array(8,3,'Schwein 1.3', 2, 12), array(9,4,'Esel 2.2.1', 3, 0), ); // Algorithmus hier $result = array(); foreach ($menu as $entry) { $result[substr(strrchr($entry[2], ' '), 1)] = $entry; } ksort($result, SORT_NATURAL); $result = array_values($result); $target = array( array(3,0,'Tiger 1', 1, 10), array(1,3,'Wurm 1.1', 2, 10), array(7,1,'Baer 1.1.1', 3, 0), array(5,3,'Katze 1.2', 2, 11), array(8,3,'Schwein 1.3', 2, 12), array(6,0,'Pferd 2', 1, 20), array(2,6,'Vogel 2.1', 2, 30), array(4,6,'Hund 2.2', 2, 40), array(9,4,'Esel 2.2.1', 3, 0),g ); var_dump($result == $target);
based on sSsDC
Output for 7.2.0
Warning: Use of undefined constant g - assumed 'g' (this will throw an Error in a future version of PHP) in /in/i3DRW on line 34 bool(false)
Output for 7.0.0 - 7.1.10
Notice: Use of undefined constant g - assumed 'g' in /in/i3DRW on line 34 bool(false)
Output for 5.4.2 - 5.6.28
Notice: Use of undefined constant g - assumed 'g' in /in/i3DRW on line 35 bool(false)
Output for 5.3.17 - 5.3.29
Notice: Use of undefined constant SORT_NATURAL - assumed 'SORT_NATURAL' in /in/i3DRW on line 20 Warning: ksort() expects parameter 2 to be long, string given in /in/i3DRW on line 20 Notice: Use of undefined constant g - assumed 'g' in /in/i3DRW on line 35 bool(false)