ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDclStack.php
Go to the documentation of this file.
1<?php
2
9class ilDclStack {
10
14 protected $stack = array();
15
16
20 public function push($elem) {
21 $this->stack[] = $elem;
22 }
23
24
28 public function pop() {
29 if (!$this->isEmpty()) {
30 $last_index = count($this->stack) - 1;
31 $elem = $this->stack[$last_index];
32 unset($this->stack[$last_index]);
33 $this->stack = array_values($this->stack); // re-index
34 return $elem;
35 }
36
37 return NULL;
38 }
39
40
44 public function top() {
45 if (!$this->isEmpty()) {
46 return $this->stack[count($this->stack) - 1];
47 }
48
49 return NULL;
50 }
51
52
56 public function isEmpty() {
57 return !(bool)count($this->stack);
58 }
59
60
61 public function reset() {
62 $this->stack = array();
63 }
64
65
69 public function count() {
70 return count($this->stack);
71 }
72
73
74 public function debug() {
75 echo "<pre>" . print_r($this->stack, 1) . "</pre>";
76 }
77}
78
79?>
Class ilDclStack.