[PHP-NOTES] note 130414 added to class.splminheap

[email protected] ("[email protected]") Fri, 11 Jul 2025 03:56:18 +0000 (UTC)
Newsgroups php.notes
Message-ID <[email protected]>
To expand on gom's comment, SplMinHeap will also take into account the subsequent elements of the array you inserted, if the elements before that are equal.

<?php 
$heap = new SplMinHeap();
$heap->insert([0, 10]);
$heap->insert([0, 30]);
$heap->insert([0, 15]);
while (!$heap->isEmpty()) {
    [$a, $b] = $heap->extract();
    echo "a:$a, b:$b\n";
}
echo "---\n";
$heap->insert([0, 10, 100]);
$heap->insert([0, 10, 300]);
$heap->insert([0, 10, 150]);
while (!$heap->isEmpty()) {
    [$a, $b, $c] = $heap->extract();
    echo "a:$a, b:$b, c:$c\n";
}
?>

will output:

a:0, b:10
a:0, b:15
a:0, b:30
---
a:0, b:10, c:100
a:0, b:10, c:150
a:0, b:10, c:300
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 103.157.49.159)
----
Manual Page -- https://php.net/manual/en/class.splminheap.php
Edit        -- https://main.php.net/note/edit/130414
Del: integrated  -- https://main.php.net/note/delete/130414/integrated
Del: useless     -- https://main.php.net/note/delete/130414/useless
Del: bad code    -- https://main.php.net/note/delete/130414/bad+code
Del: spam        -- https://main.php.net/note/delete/130414/spam
Del: non-english -- https://main.php.net/note/delete/130414/non-english
Del: in docs     -- https://main.php.net/note/delete/130414/in+docs
Del: other reasons-- https://main.php.net/note/delete/130414
Reject      -- https://main.php.net/note/reject/130414
Search      -- https://main.php.net/manage/user-notes.php