Skip to content

Instantly share code, notes, and snippets.

@kernelshreyak
Last active February 21, 2019 07:11
Show Gist options
  • Save kernelshreyak/f6a61db1f49b2566626d1998bc5ae66e to your computer and use it in GitHub Desktop.
Save kernelshreyak/f6a61db1f49b2566626d1998bc5ae66e to your computer and use it in GitHub Desktop.
PHP SPL Stack and Queue
<?php
//testing PHP Data Structures (SPL)
function displist($s){
echo "<br>";
$s->rewind();
while($s->valid()){
echo $s->current()." ";
$s->next();
}
}
$q = new SplStack();
$q[] = 1;
$q[] = 2;
$q[] = 3;
$q->push(4);
$q->add(4,5);
//View
displist($q);
$q->pop();
displist($q);
$queue = new SplQueue();
$queue->enqueue('A');
$queue->enqueue('B');
$queue->enqueue('C');
$queue->enqueue('D');
//View
displist($queue);
$queue->dequeue();
displist($queue);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment