I have a foreach loop and an if statement. If a match is found i need to ultimately break out of the foreach.
foreach ($equipxml as $equip) {
$current_device = $equip->xpath("name");
if ($current_device[0] == $device) {
// Found a match in the file.
$nodeid = $equip->id;
<break out of if and foreach here>
}
}
ifis not a loop structure, so you cannot "break out of it".You can, however, break out of the
foreachby simply callingbreak. In your example it has the desired effect:Just for completeness for others who stumble upon this question looking for an answer..
breaktakes an optional argument, which defines how many loop structures it should break. Example:Resulting output: