Jump to content

Breaking one cycle of a foreach


Omirion

Recommended Posts

very close. you use break;

 

foreach ($arr AS $value) {
   if ($value == 1) {
       break;
   }
}

 

but if you just want to skip the iteration, use continue instead

 

[code]
foreach ($arr AS $value) {
   if ($value == 1) {
       continue; // skip to the next $value
   }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.