包括“;并且“;用于单个交换机案例中的多个变量


Including "And" for multiple variables in single Switch Case

我有以下陈述,这些陈述已经过总结。我想知道如何在一个案例中显示两个变量。

如图所示,当满足date_avl和pro_qty的条件时,我希望pro_st为=0,但不确定编码的正确方式。

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' ;

如有任何建议,不胜感激。

您似乎需要一个if或可能的if/elseif语句:

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' ;
}

您只能使用switch语句来检查一个var的值,而不能像您尝试的那样检查复合条件。您可能需要使用if语句。