can you put a label to condition and loop statements so that you can break and continue them using thier label name identifier like what happens in javascript
Kendall
Label If and loop condition strucutres
Moderator: General Moderators
No you can't. But you may use break <level>; and continue <level>; constructs like this:
Code: Select all
foreach(range(1,10) as $elt) {
foreach(range(1,10) as $innerElt) {
echo "[$elt, $innerElt]";
if($innerElt>5)
continue 2; // continue outer loop
}
}
Last edited by Weirdan on Mon Nov 28, 2005 8:38 am, edited 1 time in total.
Re: Label If and loop condition strucutres
What you are describing is called a "labeled break", and currently php doesn't have one. However, there are discussions about possibly adding it in php6.kendall wrote:can you put a label to condition and loop statements so that you can break and continue them using thier label name identifier like what happens in javascript
Kendall