为什么不遵循我的条件?

时间:2014-05-25 23:02:37

标签: php foreach conditional-statements

$attributes = ['Strength_Item', 'Dexterity_Item', 'Intelligence_Item', 'Attacks_Per_Second_Percent', 'Crit_Damage_Percent',
   'Crit_Percent_Bonus_Capped', 'Hitpoints_Regen_Per_Second', 'Armor_Bonus_Item', 'Damage_Percent_Bonus_Vs_Elites'];

$cclass = 'wizard';

foreach($attributes as $i => $stat) {
   if($stat == 'Strength_Item' && ($cclass == 'crusader' || 'barbarian')){
      print($cclass);
      print($stat);
      $data += 270;
   }
}

好吧,所以如果$ stat数组出现在' Strength_Item'部分且仅当$ cclass是' crusader'或者'野蛮人'。我设置了$ cclass ='向导'。

然而,如果结果为true,则打印出' wizardStrength_Item'。这意味着cclass确实是巫师。我在这里做错了什么让我无视第二个条件?

1 个答案:

答案 0 :(得分:1)

使用以下内容:

foreach($attributes as $stat) {
   if($stat == 'Strength_Item' && ($cclass == 'crusader' || $cclass == 'barbarian')){
      print($cclass);
      print($stat);
      $data += 270;
   }
}