2013-01-23 45 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。 。 问题解决了。有用。

相关问题