<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.spl.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.iterator-to-array.php',
    1 => 'iterator_to_array',
    2 => 'Copy the iterator into an array',
  ),
  'up' => 
  array (
    0 => 'ref.spl.php',
    1 => 'SPL Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.iterator-count.php',
    1 => 'iterator_count',
  ),
  'next' => 
  array (
    0 => 'function.spl-autoload.php',
    1 => 'spl_autoload',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/spl/functions/iterator-to-array.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.iterator-to-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">iterator_to_array</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">iterator_to_array</span> &mdash; <span class="dc-title">Copy the iterator into an array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.iterator-to-array-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>iterator_to_array</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.traversable.php" class="type Traversable">Traversable</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$iterator</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$preserve_keys</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Copy the elements of an iterator into an array.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.iterator-to-array-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">iterator</code></dt>
     <dd>
      <p class="para">
       The iterator being copied.
      </p>
     </dd>
    
    
     <dt><code class="parameter">preserve_keys</code></dt>
     <dd>
      <p class="para">
       Whether to use the iterator element keys as index.
      </p>
      <p class="para">
       If a key is an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> or
       <span class="type"><a href="language.types.object.php" class="type object">object</a></span>, a warning will be generated. <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> keys will be
       converted to an empty string, <span class="type"><a href="language.types.float.php" class="type float">float</a></span> keys will be
       truncated to their <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> counterpart,
       <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> keys will generate a warning and be converted to
       their resource ID, and <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> keys will be converted to
       integers.
      </p>
      <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
       <p class="para">
        If this parameter is not set or set to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, duplicate keys will be
        overwritten. The last value with a given key will be in the returned
        <span class="type"><a href="language.types.array.php" class="type array">array</a></span>. Set this parameter to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> to get all the values
        in any case.
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.iterator-to-array-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   An <span class="type"><a href="language.types.array.php" class="type array">array</a></span> containing the elements of the <code class="parameter">iterator</code>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.iterator-to-array-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Beschreibung</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.2.0</td>
      <td>
       The type of <code class="parameter">iterator</code> has been widened from
       <span class="type"><a href="class.traversable.php" class="type Traversable">Traversable</a></span> to
       <span class="type"><span class="type"><a href="class.traversable.php" class="type Traversable">Traversable</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span></span>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.iterator-to-array-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>iterator_to_array()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$iterator </span><span style="color: #007700">= new </span><span style="color: #0000BB">ArrayIterator</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'recipe'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'pancakes'</span><span style="color: #007700">, </span><span style="color: #DD0000">'egg'</span><span style="color: #007700">, </span><span style="color: #DD0000">'milk'</span><span style="color: #007700">, </span><span style="color: #DD0000">'flour'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">iterator_to_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">iterator_to_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(4) {
  [&quot;recipe&quot;]=&gt;
  string(8) &quot;pancakes&quot;
  [0]=&gt;
  string(3) &quot;egg&quot;
  [1]=&gt;
  string(4) &quot;milk&quot;
  [2]=&gt;
  string(5) &quot;flour&quot;
}
array(4) {
  [0]=&gt;
  string(8) &quot;pancakes&quot;
  [1]=&gt;
  string(3) &quot;egg&quot;
  [2]=&gt;
  string(4) &quot;milk&quot;
  [3]=&gt;
  string(5) &quot;flour&quot;
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


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