3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class JupilerLeague extends SplHeap { /** * We modify the abstract method compare so we can sort our * rankings using the values of a given array */ public function compare($array1, $array2) { $values1 = array_values($array1); $values2 = array_values($array2); if ($values1[0] === $values2[0]) return 0; return $values1[0] < $values2[0] ? -1 : 1; } } // Let's populate our heap here (data of 2009) $heap = new JupilerLeague(); $heap->insert(array ('AA Gent' => 15)); $heap->insert(array ('Anderlecht' => 20)); $heap->insert(array ('Cercle Brugge' => 11)); $heap->insert(array ('Charleroi' => 12)); $heap->insert(array ('Club Brugge' => 21)); $heap->insert(array ('G. Beerschot' => 15)); print_r(iterator_to_array($heap)); print_r(iterator_to_array($heap));
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [5] => Array ( [Club Brugge] => 21 ) [4] => Array ( [Anderlecht] => 20 ) [3] => Array ( [AA Gent] => 15 ) [2] => Array ( [G. Beerschot] => 15 ) [1] => Array ( [Charleroi] => 12 ) [0] => Array ( [Cercle Brugge] => 11 ) ) Array ( )
Output for 5.0.0 - 5.2.17
Fatal error: Class 'SplHeap' not found in /in/KkdZ4 on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/KkdZ4 on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/KkdZ4 on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/KkdZ4 on line 9
Process exited with code 255.