xref: /PHP-8.4/ext/spl/tests/heap_003.phpt (revision 6d805ed2)
1--TEST--
2SPL: SplHeap: comparison callback
3--FILE--
4<?php
5class myHeap extends SplHeap {
6    public function compare($a, $b): int {
7        if ($a > $b) {
8            $result = 1;
9        } else if ($a < $b) {
10            $result = -1;
11        } else {
12            $result = 0;
13        }
14        return $result;
15    }
16}
17
18$h = new myHeap;
19
20$in = range(0,10);
21shuffle($in);
22foreach ($in as $i) {
23    $h->insert($i);
24}
25
26foreach ($h as $out) {
27    echo $out."\n";
28}
29?>
30--EXPECT--
3110
329
338
347
356
365
374
383
392
401
410
42