Reputation: 20173
$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;
}
But "not want to print
" is echoed. Why does continue don't apply to the foreach?
Upvotes: 3
Views: 1880
Reputation: 781769
From the http://php.net/manual/en/control-structures.continue.php:
Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue.
So use continue 2;
to continue the loop that contains it.
You also have a mismatch between $arr
and case
. The first word in the array value is no
, but you're checking for not
in the case
.
Upvotes: 7