2013-01-23 44 views
0

在下面的If .. else語句中,我想看看是否第一,有一個第四個麪包屑(URI數組4),然後看看它是否是一個數字..PHP其他語句不工作,因爲它應該.. is_numeric和isset

但雙方始終返回true,數字,字母或空..

誰能告訴我爲什麼?

// checks the third breadcrumb contained within the breadcrumbs class to see 
// if it is an article. Then uses a recursive function to search the first 
// and second breadcrumbs to see if they exist within their respective menu 
// arrays. finally, if that validates, then the fourth breadcrumb is checked 
// to see if it exists (not empty) AND if it is a number. 
else 
if (($this->breadcrumbs->getCrumb(3)=='article' && 
    $array_helper->recValueReturn($this->breadcrumbs->getCrumb(2), 
    $this->getNavTwo()) && 
    $array_helper->recValueReturn($this->breadcrumbs->getCrumb(1), 
    $this->getNavOne())) || ($this->breadcrumbs->getCrumb(4)) && 
    is_numeric($this->breadcrumbs->getCrumb(4))) { 
... 

總是以下驗證爲False:

else 
if (($this->breadcrumbs->getCrumb(3)=='article'&& 
    $array_helper->recValueReturn($this->breadcrumbs->getCrumb(2), 
    $this->getNavTwo()) && 
    $array_helper->recValueReturn($this->breadcrumbs->getCrumb(1), 
    $this->getNavOne())) && 
    (array_key_exists($this->breadcrumbs->getCrumb(4), 
     $this->breadcrumbs->getCrumbs())&& 
     is_numeric($this->breadcrumbs->getCrumb(4)))) { 
... 
+0

'$ this-> breadcrumbs-> getCrumb(3)'是什麼格式和數據? – Raptor

+0

你有沒有嘗試輸出你正在檢查的各種值? – Jim

+2

您是否嘗試過使用具有描述性名稱的函數對其進行重構,以便任何人都能知道發生了什麼,而不會盯着它幾分鐘? –

回答

1

以供將來參考,併爲別人讀這個..

的問題是在麪包類本身來解決。

上一個,麪包屑有一個包含分解URI值的私有數組。我retreived使用單一網址指數:

public function getCrumb($x) { return $this->breadcrumbs[$x] } 

但是,如果我直接修改此消氣劑包括isset:

public function getCrumb($x) { 
    if (isset($this->breadcrumbs[$x])) { 
     return $this->breadcrumbs[$x]; 
    } else { 
      return null; 
    } 
} 

,然後在OP使用第一else..if。 。 問題解決了。有用。

相關問題