©
This document uses PHP Chinese website manual Release
(PHP 5 >= 5.3.0)
SplHeap::extract — Extracts a node from top of the heap and sift up.
此函数没有参数。
The value of the extracted node.
Throws RuntimeException when the data-structure is empty.
[#1] Sandro Alves Peres [2013-06-12 13:06:53]
<?php
$heap = new SplMaxHeap(); # Ascending order
$heap->insert('E');
$heap->insert('B');
$heap->insert('D');
$heap->insert('A');
$heap->insert('C');
echo $heap->extract(), PHP_EOL; # E
echo $heap->extract(), PHP_EOL; # D
$heap = new SplMinHeap(); # Descending order
$heap->insert('E');
$heap->insert('B');
$heap->insert('D');
$heap->insert('A');
$heap->insert('C');
print PHP_EOL;
echo $heap->extract(), PHP_EOL; # A
echo $heap->extract(), PHP_EOL; # B
?>