Jump to content

How to avoid an action in the last cycle of a foreach loop?


etrader

Recommended Posts

There are many ways, but my preferred method is:

 

$firstTime = true;
foreach ($array as $tag) {
     if($firstTime) {
          echo "$tag";
          firstTime = false;
     } else {
          echo ",$tag";
     }
}

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.