Welcome Guest, Not a member yet? Register   Sign In
Can I refactor this?
#1

[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);
}
#2

[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!




Theme © iAndrew 2016 - Forum software by © MyBB