Usage of ||, OR in PHP

Posted by shin on Stack Overflow See other posts from Stack Overflow or by shin
Published on 2010-03-07T17:49:18Z Indexed on 2010/04/07 0:53 UTC
Read the original article Hit count: 560

Filed under:
|
|

I have the following code which redirect pages depends on $path.

...
$path = $this->uri->segment(3);
$pathid = $this->uri->segment(4);
if($path=='forsiden'){
            redirect('','refresh');
        }elseif($path =='contact'){
            redirect('welcome/kontakt','refresh');
        }elseif($path =='illustration'){
            $this->_gallery($path,$pathid);
        }elseif($path =='webdesign'){
            redirect('welcome/webdesign','refresh');    
        }elseif($path==('web_tjenester' || 'webdesigndetails' || 
                        'vismahjemmeside' || 'joomla' || 'vismanettbutikk' || 
                        'vpasp' || 'artportfolio')){
        ...
     CODE A   
     ...    

}else{
        ...
        CODE B
        ...
                }

I am not getting right results with

$path==('web_tjenester' || 'webdesigndetails' || 
'vismahjemmeside' || 'joomla' || 'vismanettbutikk' || 
'vpasp' || 'artportfolio')

contact, illustration, gallery and webdesign are redirected and working alright. However all other pages are added CODE A.

I am expecting CODE A only when $path is web_tjenester', 'webdesigndetails', 'vismahjemmeside', 'joomla', 'vismanettbutikk', 'vpasp' or 'artportfolio'.

Could anyone point out my mistake and correct me please?

Thanks in advance.

--UPDATE--

The following works, but is there any ways shorten the code?

I am repeating ($path==..).

elseif(($path=='web_tjenester') || ($path=='webdesigndetails') || 
    ($path=='vismahjemmeside') || ($path=='joomla') || ($path=='vismanettbutikk') || 
    ($path=='vpasp') || ($path=='artportfolio')){

© Stack Overflow or respective owner

Related posts about php

Related posts about logical-operators