<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Construct a LimitIterator</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.limititerator.html">LimitIterator</a></div> <div class="next" style="text-align: right; float: right;"><a href="limititerator.current.html">LimitIterator::current</a></div> <div class="up"><a href="class.limititerator.html">LimitIterator</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="limititerator.construct" class="refentry"> <div class="refnamediv"> <h1 class="refname">LimitIterator::__construct</h1> <p class="verinfo">(PHP 5 >= 5.1.0)</p><p class="refpurpose"><span class="refname">LimitIterator::__construct</span> — <span class="dc-title">Construct a LimitIterator</span></p> </div> <div class="refsect1 description" id="refsect1-limititerator.construct-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>LimitIterator::__construct</strong></span> ( <span class="methodparam"><span class="type"><a href="class.iterator.html" class="type Iterator">Iterator</a></span> <code class="parameter">$iterator</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code><span class="initializer"> = 0</span></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$count</code><span class="initializer"> = -1</span></span> ]] )</div> <p class="para rdfs-comment"> Constructs a new <a href="class.limititerator.html" class="classname">LimitIterator</a> from an <em><code class="parameter">iterator</code></em> with a given starting <em><code class="parameter">offset</code></em> and maximum <em><code class="parameter">count</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-limititerator.construct-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">iterator</code></em></span> <dd> <p class="para"> The <a href="class.iterator.html" class="classname">Iterator</a> to limit. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">offset</code></em></span> <dd> <p class="para"> Optional offset of the limit. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">count</code></em></span> <dd> <p class="para"> Optional count of the limit. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-limititerator.construct-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The new <a href="class.limititerator.html" class="classname">LimitIterator</a>. </p> </div> <div class="refsect1 errors" id="refsect1-limititerator.construct-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Throws an <a href="class.outofrangeexception.html" class="classname">OutOfRangeException</a> if the <em><code class="parameter">offset</code></em> is less than <em>0</em> or the <em><code class="parameter">count</code></em> is less than <em>-1</em>. </p> </div> <div class="refsect1 examples" id="refsect1-limititerator.construct-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3884"> <p><strong>Example #1 <span class="function"><strong>LimitIterator::__construct()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$ait </span><span style="color: #007700">= new </span><span style="color: #0000BB">ArrayIterator</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'a'</span><span style="color: #007700">, </span><span style="color: #DD0000">'b'</span><span style="color: #007700">, </span><span style="color: #DD0000">'c'</span><span style="color: #007700">, </span><span style="color: #DD0000">'d'</span><span style="color: #007700">, </span><span style="color: #DD0000">'e'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$lit </span><span style="color: #007700">= new </span><span style="color: #0000BB">LimitIterator</span><span style="color: #007700">(</span><span style="color: #0000BB">$ait</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">);<br />foreach (</span><span style="color: #0000BB">$lit </span><span style="color: #007700">as </span><span style="color: #0000BB">$value</span><span style="color: #007700">) {<br /> echo </span><span style="color: #0000BB">$value </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> b c d </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-limititerator.construct-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="class.limititerator.html#limititerator.examples" class="link">LimitIterator examples</a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.limititerator.html">LimitIterator</a></div> <div class="next" style="text-align: right; float: right;"><a href="limititerator.current.html">LimitIterator::current</a></div> <div class="up"><a href="class.limititerator.html">LimitIterator</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>