snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#43596

Text only

Break a loop after a certain number

1
2
3
4
5
6
7
8
$max_loop=5; //This is the desired value of Looping
$count = 0; //First we set the count to be zeo
echo "<h2> Here goes the values</h2>";
foreach($my_array as $key => $val) {
    echo "The value of $key is $val<br/>"; //Print the value of the Array
    $count++; //Increase the value of the count by 1
    if($count==$max_loop) break; //Break the loop is count is equal to the max_loop
}
https://snipt.net/embed/d772bf9ea7a11808e574884f8251b543/
https://snipt.net/raw/d772bf9ea7a11808e574884f8251b543/
d772bf9ea7a11808e574884f8251b543
text
Text only
8
2014-04-21T21:20:11
True
False
Jul 08, 2012 at 11:08 AM
/api/public/snipt/43596/
break-a-loop-after-a-certain-number
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>$max_loop=5; //This is the desired value of Looping </span><span id="L-2"><a name="L-2"></a>$count = 0; //First we set the count to be zeo </span><span id="L-3"><a name="L-3"></a>echo &quot;&lt;h2&gt; Here goes the values&lt;/h2&gt;&quot;; </span><span id="L-4"><a name="L-4"></a>foreach($my_array as $key =&gt; $val) { </span><span id="L-5"><a name="L-5"></a> echo &quot;The value of $key is $val&lt;br/&gt;&quot;; //Print the value of the Array </span><span id="L-6"><a name="L-6"></a> $count++; //Increase the value of the count by 1 </span><span id="L-7"><a name="L-7"></a> if($count==$max_loop) break; //Break the loop is count is equal to the max_loop </span><span id="L-8"><a name="L-8"></a>} </span></pre></div> </td></tr></table>
break, loop, php
#14221

CSS

Force a page break when printing a web page

1
2
3
4
5
<style type="text/css">
.pagebreak {page-break-after: always;}
</style>

<br class="pagebreak" />
https://snipt.net/embed/dc37749658f5ad304f88da92b21cba4a/
https://snipt.net/raw/dc37749658f5ad304f88da92b21cba4a/
dc37749658f5ad304f88da92b21cba4a
css
CSS
5
2014-04-23T10:16:19
True
False
/api/public/snipt/14221/
force-a-page-break-when-printing-a-web-page
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="o">&lt;</span><span class="nt">style</span> <span class="nt">type</span><span class="o">=</span><span class="s2">&quot;text/css&quot;</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="nc">.pagebreak</span> <span class="p">{</span><span class="k">page</span><span class="o">-</span><span class="n">break</span><span class="o">-</span><span class="n">after</span><span class="o">:</span> <span class="k">always</span><span class="p">;}</span> </span><span id="L-3"><a name="L-3"></a><span class="o">&lt;/</span><span class="nt">style</span><span class="o">&gt;</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="o">&lt;</span><span class="nt">br</span> <span class="nt">class</span><span class="o">=</span><span class="s2">&quot;pagebreak&quot;</span> <span class="o">/&gt;</span> </span></pre></div> </td></tr></table>
break, css, page, print, printer