Last active
September 12, 2024 06:28
-
-
Save chadyred/065ab46e15262438cf7d48307c542675 to your computer and use it in GitHub Desktop.
fifo_lifo.php
This file contains 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 | |
$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