CodeIgniter Forums
Can I refactor this? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Can I refactor this? (/showthread.php?tid=27437)



Can I refactor this? - El Forum - 02-10-2010

[eluser]koryrok[/eluser]
Hi All,

I find myself doing a lot of the following:

Code:
if ($this->uri->segment(1) == 'foo' || $this->uri->segment(1) == 'bar' ){
    $pageName = $this->uri->segment(2);
}

Whats the best way to shorten this? Why doesnt this work?

Code:
if ($this->uri->segment(1) == 'foo' || 'bar' ){
    $pageName = $this->uri->segment(2);
}



Can I refactor this? - El Forum - 02-10-2010

[eluser]Unknown[/eluser]
It's possible!

Code:
if (in_array($this->uri->segment(1), array('foo', 'bar'))){
    $pageName = $this->uri->segment(2);
}

I hope it helps!