-3
<?php
class Stack{
private $_data = array();
private $_end = null;
public function push($data){
if($this->_end === null){
$this->_end = 0;
}else{
$this->_end = $this->_end + 1;
}
$this->_data[$this->_end] = $data;
}
public function pop(){
if(empty($this->_data)){
return false;
}
$ret = $this->_data[$this->_end];
array_splice($this->_data, $this->_end);
$this->_end--;
return $ret;
}
public function getData(){
return $this->_data;
}
}
// test
$stack = new Stack();
$stack->push(0);
$pop_data = $stack->pop();
var_dump($pop_data, $stack->getData());
爲什麼不empty(0)
返回false
?我將0
推到pop_data
。 empty($this->_data)
應返回false
,但測試結果爲int(0)
。我感到困惑。爲什麼不爲空(0)返回false?
我看不出這是對的。 http://php.net/manual/en/function.empty.php說,空返回一個布爾,而不是一個int。 – Patashu 2013-04-23 03:04:15
@Patashu我不認爲他實際上質疑php函數,但他與空()renrenshang一起使用的函數我認爲這是因爲嘗試使其他語句中的代碼的其餘部分後運行的功能的其餘部分 – Breezer 2013-04-23 03:07:32
嘗試'var_dump($此 - > _數據)'。 – Raptor 2013-04-23 03:08:24