I just got bit by assuming the following:
foreach ($arr as $key => $value) {
switch($key) {
// ... some other cases
default:
continue;
// ^== assumption: move on to the next iteration of the foreach
// actual PHP: treat this continue just like a break
}
// ...
}
But in fact, according to the documentation for continue:
the switch statement is considered a looping structure for the purposes of continue.
Is there a reason for this choice on the part of PHP language designers? As far as I can tell, switch isn’t a looping control structure, so why treat it like one in this case?
Related posts:
- Break out out forloop but within switch statement php When I normally want to break out of a foreach loop before all of the...
- break; vs continue; vs return; i downloaded a free newsletter written in php from hotscripts.com i updated a little the...
- How to handle multiple xpath at once (based on feed structure) or create my own feeds with the same structure the code below is tested and working, it prints the contents of a feed that...
- How to use a switch case 'or' in PHP? is there such thing (in PHP anyway) for an OR operator in a switch case?...
- Is it possible to use || in PHP switch? switch ($foo) { case 3 || 5: bar(); break; case 2: apple(); break; } In...
- Foreach loop issues in php Here is some code I have: (p just echos plus adds a newline) foreach ($vanSteps...
- Best way to do a PHP switch with multiple values ver case? How would you do this PHP switch statement? Also note that these are much smaller...
- How to handle a PHP switch with different types? How can I make the switch respect data types ( is there a workaround better...
- PHP Coding styles return; in switch/case we’re trying to implement new coding style guidelines for our team, the php codesniffer is...
- Odd behaviour in a switch statement I’m writing code for a sortable table, where clicking the links in the header change...





