How to make an IF read two types of category at the same time?

0

Good evening, well, I want to know how I can put: if ($this->GetCategoryName() == 'mmorpg' OR 'shots') in the same line of code, without having to do this:

if ($this->GetCategoryName() == 'mmorpg') {
    if ($this->GetCategoryName() == 'shots') {
        $url = $c_url;
    } else {
        $url = $c_url;
    }
} else {
    $url = U_LANG.'/'.$url_cat;
}
    
asked by anonymous 08.10.2018 / 02:35

1 answer

4

So:

if ($this->GetCategoryName() == 'mmorpg' && $this->GetCategoryName() == 'shots') {

But it has a logic error, if it is one thing it is not another.

In PHP you can use

  • && to AND

  • || to OR, is not that what you're looking for?

But maybe you're more interested in doing this:

$cat = $this->GetCategoryName();
$url = ($cat == 'mmorpg' || $cat == 'shots') ? 'url1' : 'url2';

That is, "if the category is mmorpg OR category is shots, it is url1, else url2"


Note that PHP has and and or too, but change the precedence, see here:

  

What's the difference between "& &" and "||" and "and" and "or" in PHP? Which one to use?

    
08.10.2018 / 02:38