php: counter break after 4 items then start another with new div

186 views Asked by At

I want a little help regarding my code. So basically what i want is add a div after 4,5 or 6 items.. doesn't matter how much items. After that, i used break to stop the counter then start another one but it's doesn't work. Know why; because i used break.

    $modules= &JModuleHelper::getModules('something_module_name');          
        if(count($modules)>0){
            if(++$counter % 6 === 0) {
            echo '<div id="something_module_class clearfix">';
            foreach (array_keys($modules) as $m){
                echo JModuleHelper::renderModule($modules[$m],$mod_attribs);
              }
            echo'</div>';
            break;

             }
          }

After 6 items, the counter will stop because of the "Break".

<div class="item">
<div class="item">
<div class="item">
<div class="item">
<div class="item">
<div id="somehting clearfix">

If i don't use the break then it will repeat every 6 items, with the same echo or div. What i want is every 6 items another div.

    <div class="item">
    <div class="item">
    <div class="item">
    <div class="item">
    <div class="item">
    <div id="somehting clearfix">
     <div class="item">
    <div class="item">
    <div class="item">
    <div class="item">
    <div class="item">
<div id="somehting else somehting else clearfix">
1

There are 1 answers

0
PcWolf On

I used this:

foreach(bla bla bla){
 if($counter== 2){code}
------------------
 if($counter== 8){code}
            $counter++;
}

This worked for my.