<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.array.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.each.php',
    1 => 'each',
    2 => 'Return the current key and value pair from an array and advance the array cursor',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Функції для роботи з масивами',
  ),
  'prev' => 
  array (
    0 => 'function.current.php',
    1 => 'current',
  ),
  'next' => 
  array (
    0 => 'function.end.php',
    1 => 'end',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/array/functions/each.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.each" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">each</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">each</span> &mdash; <span class="dc-title">Return the current key and value pair from an array and advance the array cursor</span></p>

 </div>

 <div id="function.each-refsynopsisdiv">
   <div class="warning"><strong class="warning">Увага</strong><p class="simpara">Ця функція
<em>ЗАСТАРІЛА</em>, починаючи з PHP 7.2.0, та
<em>ВИЛУЧЕНА</em> в PHP 8.0.0. Вкрай не рекомендується на неї
покладатися.</p></div>
 </div>

 <div class="refsect1 description" id="refsect1-function.each-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>each</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.object.php" class="type object">object</a></span></span> <code class="parameter reference">&$array</code></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Return the current key and value pair from an array and advance the array
   cursor.
  </p>
  <p class="para">
   After <span class="function"><strong>each()</strong></span> has executed, the array cursor
   will be left on the next element of the array, or past the last
   element if it hits the end of the array. You have to use
   <span class="function"><a href="function.reset.php" class="function">reset()</a></span> if you want to traverse the array
   again using each.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.each-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       The input array.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.each-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns the current key and value pair from the array
   <code class="parameter">array</code>. This pair is returned in a four-element
   array, with the keys <code class="literal">0</code>, <code class="literal">1</code>,
   <code class="literal">key</code>, and <code class="literal">value</code>. Elements
   <code class="literal">0</code> and <code class="literal">key</code> contain the key name of
   the array element, and <code class="literal">1</code> and <code class="literal">value</code>
   contain the data.
  </p>
  <p class="para">
   If the internal pointer for the array points past the end of the
   array contents, <span class="function"><strong>each()</strong></span> returns
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.each-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>each()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="annotation-non-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$foo </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"bob"</span><span style="color: #007700">, </span><span style="color: #DD0000">"fred"</span><span style="color: #007700">, </span><span style="color: #DD0000">"jussi"</span><span style="color: #007700">, </span><span style="color: #DD0000">"jouni"</span><span style="color: #007700">, </span><span style="color: #DD0000">"egon"</span><span style="color: #007700">, </span><span style="color: #DD0000">"marliese"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= </span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>
     <var class="varname">$bar</var> now contains the following key/value
     pairs:
    </p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [1] =&gt; bob
    [value] =&gt; bob
    [0] =&gt; 0
    [key] =&gt; 0
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="informalexample">
    <div class="example-contents">
<div class="annotation-non-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$foo </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Robert" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"Bob"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Seppo" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"Sepi"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= </span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <p class="para">
     <var class="varname">$bar</var> now contains the following key/value
     pairs:
    </p>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [1] =&gt; Bob
    [value] =&gt; Bob
    [0] =&gt; Robert
    [key] =&gt; Robert
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <span class="function"><strong>each()</strong></span> is typically used in conjunction with
   <span class="function"><a href="function.list.php" class="function">list()</a></span> to traverse an array, here&#039;s an
   example:
   <div class="example" id="example-2">
    <p><strong>Приклад #2 Traversing an array with <span class="function"><strong>each()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-non-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fruit </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'a' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'apple'</span><span style="color: #007700">, </span><span style="color: #DD0000">'b' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'banana'</span><span style="color: #007700">, </span><span style="color: #DD0000">'c' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'cranberry'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">reset</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruit</span><span style="color: #007700">);<br />while (list(</span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">$val</span><span style="color: #007700">) = </span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruit</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000"> =&gt; </span><span style="color: #0000BB">$val</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">a =&gt; apple
b =&gt; banana
c =&gt; cranberry</pre>
</div>
    </div>
   </div>
  </p>
  <div class="caution"><strong class="caution">Застереження</strong>
   <p class="para">
    Because assigning an array to another variable resets the original
    array&#039;s pointer, our example above would cause an endless loop had we
    assigned <var class="varname">$fruit</var> to another variable inside the
    loop.
   </p>
  </div>
  <div class="warning"><strong class="warning">Увага</strong>
   <p class="para">
    <span class="function"><strong>each()</strong></span> will also accept objects, but may return unexpected 
    results. It&#039;s therefore not recommended to iterate though object properties 
    with <span class="function"><strong>each()</strong></span>.
   </p>
  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.each-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.key.php" class="function" rel="rdfs-seeAlso">key()</a> - Fetch a key from an array</span></li>
    <li><span class="function"><a href="function.list.php" class="function" rel="rdfs-seeAlso">list()</a> - Assign variables as if they were an array</span></li>
    <li><span class="function"><a href="function.current.php" class="function" rel="rdfs-seeAlso">current()</a> - Return the current element in an array</span></li>
    <li><span class="function"><a href="function.reset.php" class="function" rel="rdfs-seeAlso">reset()</a> - Встановлює внутрішній вказівних масиву на його перший елемент</span></li>
    <li><span class="function"><a href="function.next.php" class="function" rel="rdfs-seeAlso">next()</a> - Advance the internal pointer of an array</span></li>
    <li><span class="function"><a href="function.prev.php" class="function" rel="rdfs-seeAlso">prev()</a> - Rewind the internal array pointer</span></li>
    <li><a href="control-structures.foreach.php" class="link">foreach</a></li>
    <li><a href="language.oop5.iterations.php" class="link">Object Iteration</a></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>