Skip to content

Instantly share code, notes, and snippets.

@chadyred
Last active September 12, 2024 06:28
Show Gist options
  • Save chadyred/065ab46e15262438cf7d48307c542675 to your computer and use it in GitHub Desktop.
Save chadyred/065ab46e15262438cf7d48307c542675 to your computer and use it in GitHub Desktop.
fifo_lifo.php
<?php
$array = ['H', 'E', 'L', 'L', 'O', 1.1];
$stackLifo = new ArrayIterator(['D', 'L', 'R', 'O', 'W']);
$stackLifoAsArray = $stackLifo->getArrayCopy();
// Add left to the stack (the last added, will be the first out)
array_push($stackLifoAsArray, ' ');
array_push($stackLifoAsArray, 'Hello');
foreach ($stackLifoAsArray as $el) {
echo array_pop($stackLifoAsArray) . ' '; // empty stack
}
var_dump(memory_get_usage());
// FIFO simple as hell
$queue = ['first task', 'second task', 'third task', 'forth task'];
$count = count($queue);
$i = 0;
while ($i <= $count) {
echo array_shift($queue) . ' '; // empty queue
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment