在switch语句内部使用continue跳过foreach迭代

3
$arr = array('not want to print','foo','bar');

foreach($arr as $item) {
  switch($item) {
      case 'foo':
         $item = 'bar';
         break;
      case 'not want to print':
         continue;
         break;
  }

  echo $item;
}

但是输出了“not want to print”。为什么continue语句没有作用于foreach循环中呢? http://codepad.org/WvW1Fmmo

你拼错了 switch。这是真正的代码还是复制错误? - Barmar
嗨,谢谢;不,这实际上是一个示例 http://codepad.org/Ytkd8x2M - Toni Michel Caubet
1
'no want to print' 和 'not want to print' - 打字错误 - jancha
1个回答

7

谢谢你提醒我,之前我从未听说过这个。实际上我的代码更长,也没有拼写错误,我尝试复制一个简化版本的代码,哈哈。再次感谢! - Toni Michel Caubet

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接