开发者

php URI troube with if statement,

开发者 https://www.devze.com 2022-12-27 17:46 出处:网络
I am running an if statement, that looks like this, if($this->uri->segment(1) !== \'search\' || $this->uri->segment(1) !== \'employment\') {

I am running an if statement, that looks like this,

if($this->uri->segment(1) !== 'search' || $this->uri->segment(1) !== 'employment') {
    //dome something
}

My problem is that first condition works, if the uri segment 1 equals search then the method do not ru开发者_JAVA技巧n however if I on the page employment, and the first segment of the uri is employment then the condition still runs, why is this?


you have to do

if($this->uri->segment(1) === 'search' || $this->uri->segment(1) === 'employment') {
    //do something
}

or

if($this->uri->segment(1) !== 'search' && $this->uri->segment(1) !== 'employment') {
    //do something
}

depending on what you want to do... asking for (bla!=blubb || bla!=blah) doen't make any sense because it will be true everytime.


You are looking for this i think:

if($this->uri->segment(1) === 'search' || $this->uri->segment(1) === 'employment') {
    //dome something
}

Use === instead of !==

0

精彩评论

暂无评论...
验证码 换一张
取 消