Last active
February 21, 2019 07:11
-
-
Save kernelshreyak/f6a61db1f49b2566626d1998bc5ae66e to your computer and use it in GitHub Desktop.
PHP SPL Stack and Queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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