I would use a do while inside the foreach
foreach($furniture as $fur){
//do something
do{
if($fur->broken == true){
//do something
break;
}
}while(false);
}
The Do While evaluates the condition after the first iteration, in this case the loop ends after the first iteration (because the condition is false), but this gives us a structure we can break out of.
The other way to do this is to use a switch statement with an if in it.
foreach($furniture as $fur){
//do something
switch(1){
default:
if($fur->broken == true){
//do something
break;
}
}
}
Also note to break out of the foreach you can do break 2
instead of just break
.
All that said, I would say just from a best practice standpoint this makes the code less readable and what you need could be done without it ( most likely ) but I would need more details to help with that.
UPDATE
IS this a template thing like ( Blade )? It's not clear in the question. I don't use blade, but I've seen it, studied it some, so that makes sense with the @
sign. But as I took the time to type this I'll leave it here.
Of note the same could probably be done in blade by faking a loop ( loop 1 time ) inside the foreach, same principle as the do while. Assuming it supports break levels. Something like this
@foreach($furniture as $fur)
//do something
@foreach($fake as $f)
@if($fur->broken == true)
//do something
@break
@endif
@endforeach
//do something else
@endforeach
//where fake is like $fake = [1]; single element, so one loop.
You could also do the extra loop inside or outside the if block, as your needs dictate.
I am also not sure if Blade supports switch
most template engines don't, but it may be cleaner to use if it does.