<?php
class Stack {
private $array = array(2, 3, 4, 5);
public function print_array(){
print_r( $this->array );
}
public function push_to_array($value){
$this->array[] = $value;
}
public function pop_from_array(){
$count = count($this->array) - 1;
if(empty($this->array[$count])){
echo 'array is empty';
} else{
$pop_value = $this->array[$count];
unset($this->array[$count]);
return $pop_value;
}
}
public function last(){
if(empty($this->array[0])){
return 'array is empty';
} else{
return $this->array[0];
}
}
public function first(){
$count = count($this->array) - 1;
if(empty($this->array[$count])){
return 'array is empty';
} else{
return $this->array[$count];
}
}
}
$array = new Stack();
echo $array->pop_from_array();
$array->print_array();
class Stack {
private $array = array(2, 3, 4, 5);
public function print_array(){
print_r( $this->array );
}
public function push_to_array($value){
$this->array[] = $value;
}
public function pop_from_array(){
$count = count($this->array) - 1;
if(empty($this->array[$count])){
echo 'array is empty';
} else{
$pop_value = $this->array[$count];
unset($this->array[$count]);
return $pop_value;
}
}
public function last(){
if(empty($this->array[0])){
return 'array is empty';
} else{
return $this->array[0];
}
}
public function first(){
$count = count($this->array) - 1;
if(empty($this->array[$count])){
return 'array is empty';
} else{
return $this->array[$count];
}
}
}
$array = new Stack();
echo $array->pop_from_array();
$array->print_array();
No comments:
Post a Comment