correct use of break in 'if' loop question
Posted: Mon Sep 13, 2010 12:27 pm
I have an if loop like this:But when I input a valid (matching) string, I get an error: PHP Fatal error: But I'd like to understand the correct way to do this.
Thanks,
--cz
Code: Select all
if($zip!=""){
if(preg_match('/^\d{5}(-\d{4})?$/',$zip)){
break 2;
} else {
$errors=1;
$error.="<li>Please enter a valid <abbr>us</abbr> ZIP code (5 digit ZIP or ZIP + 4)</li>";
}
}
I've worked around this withCannot break/continue 1 level in path/to/file.php on line xyz
Code: Select all
if($zip!=""){
if(preg_match('/^\d{5}(-\d{4})?$/',$zip)){
$errors=$errors;
} else {
$errors=1;
$error.="<li>Please enter a valid <abbr>us</abbr> ZIP code (5 digit ZIP or ZIP + 4)</li>";
}
}Thanks,
--cz