ILIAS  release_8 Revision v8.24
class.ilDclStack.php
Go to the documentation of this file.
1<?php
2
20{
21 protected array $stack = array();
22
26 public function push($elem)
27 {
28 $this->stack[] = $elem;
29 }
30
34 public function pop()
35 {
36 if (!$this->isEmpty()) {
37 $last_index = count($this->stack) - 1;
38 $elem = $this->stack[$last_index];
39 unset($this->stack[$last_index]);
40 $this->stack = array_values($this->stack); // re-index
41
42 return $elem;
43 }
44
45 return null;
46 }
47
51 public function top()
52 {
53 if (!$this->isEmpty()) {
54 return $this->stack[count($this->stack) - 1];
55 }
56
57 return null;
58 }
59
60 public function isEmpty(): bool
61 {
62 return !(bool) count($this->stack);
63 }
64
65 public function reset(): void
66 {
67 $this->stack = array();
68 }
69
70 public function count(): int
71 {
72 return count($this->stack);
73 }
74
75 public function debug(): void
76 {
77 echo "<pre>" . print_r($this->stack, 1) . "</pre>";
78 }
79}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...