简体   繁体   中英

PHP elseif when value 0

i have a problem with the following code. If the next 3qty, 4qty or 5qty is 0, i cant get my actual value. I need something like: if 3qty = 0 -> ignore

if($volume >= $1qty && $volume < $2qty)
{
$actual = $one;
}
elseif($volume >= $2qty && $volume < $3qty)
{
$actual = $two;
}
elseif($volume >= $3qty && $volume < $4qty)
{
$actual = $three;
}
elseif($volume >= $4qty && $volume < $5qty)
{
$actual = $four;
}
elseif($volume >= $5qty)
{
$actual = $five;
}

i hope someone can help me, i cant get a solution for my problem by my self :/

 if($1qty != 0){ if($volume >= $1qty && $volume < $2qty){ $actual = $one; } elseif($volume >= $2qty && $volume < $3qty){ $actual = $two; } elseif($volume >= $3qty && $volume < $4qty){ $actual = $three; } elseif($volume >= $4qty && $volume < $5qty){ $actual = $four; } elseif($volume >= $5qty){ $actual = $five; }; } 

at the beginning I'm validating that is, if it is not, continue

Try this:

if( $2qty>0 && $3qty>0 && $4qty>0 && $5qty>0 ) {
    if( $volume>=$1qty && $volume<$2qty ) {
        $actual = $one;
    } else if( $volume>=$2qty && $volume<$3qty ) {
        $actual = $two;
    } else if( $volume>=$3qty && $volume<$4qty ) {
        $actual = $three;
    } else if( $volume>=$4qty && $volume<$5qty ) {
        $actual = $four;
    } else if( $volume>=$5qty ) {
        $actual = $five;
    } else {
        $actual = false;
    }
} else {
    $actual = false;
}

the following work finde:

if($1qty != 0 && $2qty != 0 && $3qty == 0 && $4qty == 0 && $5qty == 0){
if($volume >= $1qty && $volume < $2qty)
{
$actual = $one;
}
elseif($volume >= $2qty)
{
$actual = $two;
}
elseif($1qty != 0 && $2qty != 0 && $3qty != 0 && $4qty == 0 && $5qty == 0){
if($volume >= $1qty && $volume < $2qty)
{
$actual = $one;
}
elseif($volume >= $2qty && $volume < $3qty)
{
$actual = $two;
}
elseif($volume >= $3qty)
{
$actual = $three;
}

and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM