<?php
$iterator = new GlobIterator('/var/log/*.log');
foreach($iterator as $file) {
echo $file->getFilename();
echo "<br>";
}
?><?php
$q = new SplStack();
$q[] = 1;
$q[] = 2;
$q[] = 3;
foreach ($q as $elem) {
echo $elem."<br>\n";
}
?><?php
$heap = new SplMaxHeap();
$heap->insert(2);
$heap->insert(1);
$heap->insert(3);
foreach ($heap as $elem) {
echo $elem."<br>\n";
}
?><?php
class PQ extends SplPriorityQueue {
private $pris = array('high'=>3,'medium'=>2,'low'=>1);
public function compare($pri1, $pri2) {
if ($pri1==$pri2) return 0;
return ($this->pris[$pri1]<$this->pris[$pri2]) ? -1 : 1;
}
}
$PQ = new PQ();
$PQ->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
$PQ->insert('Run','medium');
$PQ->insert('Sleep', 'high');
$PQ->insert('Fix annoying bug','low');
$PQ->insert('Eat','high');
foreach($PQ as $task) {
echo "{$task['data']} -- {$task['priority']}<br>\n";
}
?>