<?php
class MyHeap extends SplHeap
{
/**
* @see http://www.php.net/manual/en/splheap.compare.php
*/
protected function compare($val1, $val2)
{
return strlen((string) $val1) -
strlen((string) $val2);
}
}
$heap = new MyHeap();
$heap->insert('----');
$heap->insert('---');
$heap->insert('-');
$heap->insert('--');
echo 'elements in heap: ' . count($heap) . PHP_EOL;
foreach($heap as $val) {
echo $val . PHP_EOL;
}
echo 'elements in heap: ' . count($heap);