开发者

PHP Conditionals --> If Else with multiple decisions

开发者 https://www.devze.com 2023-02-10 19:57 出处:网络
if I have something like: if (($browser->getBrowser() == Browser::BROW开发者_StackOverflowSER_SAFARI && $browser->getVersion() >= 3 ) ||

if I have something like:

if (($browser->getBrowser() == Browser::BROW开发者_StackOverflowSER_SAFARI && $browser->getVersion() >= 3 ) ||
    ($browser->getBrowser() == Browser::BROWSER_CHROME && $browser->getVersion() >= 5 ))
{
    // code here
}

but I really want to say also if Chrome >= 5 but less 6...

I will add an else if for 6+

later on in else () less than version 5 would fall into..

How would I write >= 5 but < 6?


So you can do this directly by adding another condition:

if (($browser->getBrowser() == Browser::BROWSER_SAFARI 
     && $browser->getVersion() >= 3 ) ||
    ($browser->getBrowser() == Browser::BROWSER_CHROME 
     && $browser->getVersion() >= 5 && $browser->getVersion() < 6 ))
{
    // code here
}

I'm assuming getVersion must be capable of returning non-integer numbers, otherwise you could just check for equality ($browser->getVersion() == 5).

0

精彩评论

暂无评论...
验证码 换一张
取 消