Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #16609

Re: break foreach loop after certain iteration and then start it

From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: break foreach loop after certain iteration and then start it
Date 2016-03-04 09:27 +0100
Message-ID <56D946D4.9030504@arnowelzel.de> (permalink)
References <6586983f-c3bc-4eb7-92a3-6035952e8cbb@googlegroups.com>

Show all headers | View raw


apoorv.kanungo@gmail.com schrieb am 2016-03-04 um 07:08:
> Hello I have a foreach loop foreach($product as $products) and I want
> to stop that after three iteration and output some html like <div
> id="logo"></div>and after that div I want to continue the loop after
> three iteration.
> 
> I know we can break foreach loop after certain iteration with if
> condition and break it but how would you continue the loop after
> break.

<?php
$counter = 0;

foreach($mylist as $element)
{
    // Do something with $element

    // Add something every three elements
    $counter++;
    if($counter==3)
    {
        echo '<div id="logo"></div>';
        $counter = 0;
    }
}
?>

-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

break foreach loop after certain iteration and then start it apoorv.kanungo@gmail.com - 2016-03-03 22:08 -0800
  Re: break foreach loop after certain iteration and then start it Arno Welzel <usenet@arnowelzel.de> - 2016-03-04 09:27 +0100
    Re: break foreach loop after certain iteration and then start it Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-05 02:28 +0100
      Re: break foreach loop after certain iteration and then start it Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-04 21:32 -0500
      Re: break foreach loop after certain iteration and then start it Arno Welzel <usenet@arnowelzel.de> - 2016-03-05 10:52 +0100
        Re: break foreach loop after certain iteration and then start it Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-05 11:46 +0100
          Re: break foreach loop after certain iteration and then start it Tim Streater <timstreater@greenbee.net> - 2016-03-05 12:08 +0000
          Re: break foreach loop after certain iteration and then start it Arno Welzel <usenet@arnowelzel.de> - 2016-03-05 14:10 +0100
            Re: break foreach loop after certain iteration and then start it Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-05 17:55 +0100
          Re: break foreach loop after certain iteration and then start it Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-05 08:50 -0500
            Re: break foreach loop after certain iteration and then start it Arno Welzel <usenet@arnowelzel.de> - 2016-03-06 10:57 +0100
              Re: break foreach loop after certain iteration and then start it Tim Streater <timstreater@greenbee.net> - 2016-03-06 11:26 +0000
              Re: break foreach loop after certain iteration and then start it Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-06 10:12 -0500
                Re: break foreach loop after certain iteration and then start it Arno Welzel <usenet@arnowelzel.de> - 2016-03-06 22:48 +0100
                Re: break foreach loop after certain iteration and then start it Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-06 20:49 -0500
                Re: break foreach loop after certain iteration and then start it "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-03-07 16:28 +0100
                Re: break foreach loop after certain iteration and then start it Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-07 12:38 -0500
                Re: break foreach loop after certain iteration and then start it Arno Welzel <usenet@arnowelzel.de> - 2016-03-07 17:42 +0100
                Re: break foreach loop after certain iteration and then start it Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-07 12:39 -0500
                Re: break foreach loop after certain iteration and then start it Arno Welzel <usenet@arnowelzel.de> - 2016-03-09 08:18 +0100
                Re: break foreach loop after certain iteration and then start it "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-03-09 10:05 +0100
                Re: break foreach loop after certain iteration and then start it Jerry Stuckle <jstucklex@attglobal.net> - 2016-03-09 08:56 -0500
  Re: break foreach loop after certain iteration and then start it "R.Wieser" <address@not.available> - 2016-03-04 09:34 +0100

csiph-web