- array_shift: documentation ( source)
- array_pop: documentation ( source)
<?php declare(strict_types=1);
final class Stacker {
private array $stack = [];
public function push($obj): Stacker {
$this->stack[] = $obj;
return $this;
}
public function shift() {
return array_shift($this->stack);
}
public function pop() {
return array_pop($this->stack);
}
}
$stack = new Stacker();
$stack->push(1);