Let's "do stuff" with array_pop()
<?php
$dependecyInjection = ['globalState' => 'isHorrible'];
$workQueue = array_reverse($workQueue); // O(n)
// While we have stuff to do..... = [[ {function}, $params.... ], [], []...]
while (!empty($workQueue)) {
// O(1) : And resize array. (maybe also memory size ?)
$work = array_pop($workQueue);
// If not `muted`, invoke the worker function....
if (isset($work[0])) {
$processor = array_shift($work);
if ($moreWork = $processor->__invoke($work, $dependecyInjection)) { // <== Do stuff.
// O(n) : add new stuff to the END of array ! (FIFO)
$outputCommands += array_reverse($moreWork);
}
}
}