The SplStack has many functions for accessing its elements, but is there a way to clear it? Or should I "clear" my stack by replacing it with a new, empty stack?
There is no built-in method to clear a stack.
You'd either need to clear it down using pops or unsets:
while($stack->valid()) {
$stack->pop();
}
Or unset the stack itself, and create a new one:
unset($stack);
$stack = new \SplStack();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.