Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including "And" for multiple variables in single Switch Case [duplicate]

I have the following statement, which has been summarised. I was wondering how to show two variables in a single case.

As shown I want pro_st to = 0 when the criteria for both date_avl and pro_qty have been met, but not sure of the correct way to code it.

case $insert_pro :
    case $pro_exists_row['date_aval'] == '0000-00-00' : and $sql_data['pro_qty'] == 0 :
    case $sql_data['pro_date_avl'] > date('Y-m-d') :
      $sql_data['pro_st'] = '0' ;
      break ;
    default :
      $sql_data['pro_st'] = '1' ;

Any advise would be appreciated.

like image 255
user1633094 Avatar asked Dec 31 '25 21:12

user1633094


1 Answers

You look like you need an if or possible an if/elseif statement:

if (( $pro_exists_row['date_aval'] == '0000-00-00' && $sql_data['pro_qty'] == 0 ) || $sql_data['pro_date_avl'] > date('Y-m-d'))
{
    // This is the first two conditions of you case statement - either of the conditions are met
    $sql_data['pro_st'] = '0' ;
}
else
{
    // This is he default as neither of the others were met...
    $sql_data['pro_st'] = '1' ;
}
like image 70
Fluffeh Avatar answered Jan 03 '26 11:01

Fluffeh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!