@ 2014-04-10T15:11:20Z <?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(clone $heap));
print_r(iterator_to_array(clone $heap));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Deprecated: Return type of JupilerLeague::compare($array1, $array2) should either be compatible with SplHeap::compare(mixed $value1, mixed $value2): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4nP0r on line 9
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
(
[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
)
)
Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 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
(
[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
)
)
Output for 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Fatal error: Class 'SplHeap' not found in /in/4nP0r 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/4nP0r on line 9
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/4nP0r 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/4nP0r on line 9
Process exited with code 255 . preferences:dark mode live preview
241.18 ms | 401 KiB | 356 Q