php URI troube with if statement,
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 !==
精彩评论