Datastack¶
A data stack is a LIFO data structure: the last data added to the stack is the first to get out.
In PHP, a data stack may be implemented with an array, and the array_push(), or $array[] operator, and the array_pop() functions.
There is also a class called SplStack, in the spl extension, and Ds\Stack in the ds extension.
<?php
$stack = [];
$stack[] = first;
$stack[] = second;
// same as array_push($stack, second);
echo array_pop($stack); // Outputs: second
?>
See also DsStack.
Related : SplStack, Data Structure, Standard PHP Library (SPL), Last In, First Out (LIFO), Deque, Queue, Stack