<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.list.php',
    1 => 'list',
    2 => 'Weist Variablen zu, als w&auml;ren sie ein Array',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Array Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.ksort.php',
    1 => 'ksort',
  ),
  'next' => 
  array (
    0 => 'function.natcasesort.php',
    1 => 'natcasesort',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'reference/array/functions/list.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.list" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">list</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">list</span> &mdash; <span class="dc-title">Weist Variablen zu, als wären sie ein Array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.list-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>list</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$vars</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Wie <span class="function"><a href="function.array.php" class="function">array()</a></span> ist auch dies keine Funktion, sondern ein
   Sprachkonstrukt. <span class="function"><strong>list()</strong></span> wird verwendet, um eine Liste
   von Variablen in einer Operation zuzuweisen. Zeichenketten können nicht
   verarbeitet werden und der <span class="function"><strong>list()</strong></span>-Ausdruck darf nicht
   vollständig leer sein.
  </p>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Vor PHP 7.1.0 funktionierte <span class="function"><strong>list()</strong></span> nur bei numerischen
    Arrays und basierte auf der Annahme, dass die numerischen Indizes bei 0
    beginnen.
   </p>
  </p></blockquote>
  <p class="para">
   Seit PHP 7.1.0 kann <span class="function"><strong>list()</strong></span> auch explizite Schlüssel
   enthalten, sodass Arrays mit nicht-ganzzahligen oder nicht-sequentiellen
   Schlüsseln destrukturiert werden können. Weitere Details zur
   Destrukturierung von Arrays sind im Abschnitt
   <a href="language.types.array.php#language.types.array.syntax.destructuring" class="link">Destrukturierung von Arrays</a> zu
   finden.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.list-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">var</code></dt>
     <dd>
      <p class="para">
       Eine Variable.
      </p>
     </dd>
    
   </dl>
   <dl>
    
     <dt><code class="parameter">vars</code></dt>
     <dd>
      <p class="para">
       Weitere Variablen.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.list-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt das zugewiesene Array zurück.
  </p>
 </div>


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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.3.0</td>
       <td>
        Die Unterstützung von Referenzzuweisungen bei der
        Arraydestrukturierung wurde hinzugefügt.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Es ist nun möglich, Schlüssel in <span class="function"><strong>list()</strong></span> anzugeben.
        Dies ermöglicht die Destrukturierung von Arrays mit nicht-numerischen
        oder nicht-fortlaufenden Schlüsseln.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.list-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>list()</strong></span>-Beispiele</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$info </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'Kaffee'</span><span style="color: #007700">, </span><span style="color: #DD0000">'braun'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Koffein'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Auflisten aller Variablen<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$drink</span><span style="color: #007700">, </span><span style="color: #0000BB">$color</span><span style="color: #007700">, </span><span style="color: #0000BB">$power</span><span style="color: #007700">) = </span><span style="color: #0000BB">$info</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$drink</span><span style="color: #DD0000"> ist </span><span style="color: #0000BB">$color</span><span style="color: #DD0000"> und </span><span style="color: #0000BB">$power</span><span style="color: #DD0000"> macht es zu etwas Besonderem.\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Ein paar davon auflisten<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$drink</span><span style="color: #007700">, , </span><span style="color: #0000BB">$power</span><span style="color: #007700">) = </span><span style="color: #0000BB">$info</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$drink</span><span style="color: #DD0000"> hat </span><span style="color: #0000BB">$power</span><span style="color: #DD0000">.\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Oder nur die dritte ausgeben<br /></span><span style="color: #007700">list( , , </span><span style="color: #0000BB">$power</span><span style="color: #007700">) = </span><span style="color: #0000BB">$info</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"Ich brauche </span><span style="color: #0000BB">$power</span><span style="color: #DD0000">!\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// list() funktioniert nicht mit Zeichenketten<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">) = </span><span style="color: #DD0000">"abcde"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">); </span><span style="color: #FF8000">// NULL<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Beispiel #2 Ein Beispiel für die Verwendung von <span class="function"><strong>list()</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 />$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$pdo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id, name FROM employees"</span><span style="color: #007700">);<br />while (list(</span><span style="color: #0000BB">$id</span><span style="color: #007700">, </span><span style="color: #0000BB">$name</span><span style="color: #007700">) = </span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_NUM</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"id: </span><span style="color: #0000BB">$id</span><span style="color: #DD0000">, name: </span><span style="color: #0000BB">$name</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>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Beispiel #3 Verschachtelte <span class="function"><strong>list()</strong></span>-Ausdrücke verwenden</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, list(</span><span style="color: #0000BB">$b</span><span style="color: #007700">, </span><span style="color: #0000BB">$c</span><span style="color: #007700">)) = array(</span><span style="color: #0000BB">1</span><span style="color: #007700">, array(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, </span><span style="color: #0000BB">$b</span><span style="color: #007700">, </span><span style="color: #0000BB">$c</span><span style="color: #007700">);<br /><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="annotation-interactive examplescode"><pre class="examplescode">int(1)
int(2)
int(3)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   Die Reihenfolge, in der die Indizes des von <span class="function"><strong>list()</strong></span> zu
   verarbeitenden Arrays definiert werden, ist irrelevant.
  </p>
  <p class="para">
   <div class="example" id="example-4">
    <p><strong>Beispiel #4 <span class="function"><strong>list()</strong></span> und die Reihenfolge der Index-Definitionen</strong></p>
    <div class="example-contents">
<div class="annotation-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: #0000BB">2 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'a'</span><span style="color: #007700">, </span><span style="color: #DD0000">'foo' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'b'</span><span style="color: #007700">, </span><span style="color: #0000BB">0 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'c'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$foo</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] = </span><span style="color: #DD0000">'d'</span><span style="color: #007700">;<br />list(</span><span style="color: #0000BB">$x</span><span style="color: #007700">, </span><span style="color: #0000BB">$y</span><span style="color: #007700">, </span><span style="color: #0000BB">$z</span><span style="color: #007700">) = </span><span style="color: #0000BB">$foo</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #0000BB">$x</span><span style="color: #007700">, </span><span style="color: #0000BB">$y</span><span style="color: #007700">, </span><span style="color: #0000BB">$z</span><span style="color: #007700">);</span></span></code></div>
    </div>

    <div class="example-contents"><p>
     Erzeugt folgende Ausgabe (beachten Sie die Reihenfolge der Elemente
     verglichen mit der in <span class="function"><strong>list()</strong></span> eingetragenen
     Reihenfolge):
    </p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(4) {
  [2]=&gt;
  string(1) &quot;a&quot;
  [&quot;foo&quot;]=&gt;
  string(1) &quot;b&quot;
  [0]=&gt;
  string(1) &quot;c&quot;
  [1]=&gt;
  string(1) &quot;d&quot;
}
string(1) &quot;c&quot;
string(1) &quot;d&quot;
string(1) &quot;a&quot;</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5">
    <p><strong>Beispiel #5 <span class="function"><strong>list()</strong></span> mit Schlüsseln</strong></p>
    <div class="example-contents"><p>
     Von PHP 7.1.0 an kann <span class="function"><strong>list()</strong></span> nun ebenfalls explizite
     Schlüssel enthalten, die als beliebige Ausdrücke angegeben werden können.
     Die Kombination von Integer- und Zeichenkettenschlüsseln ist erlaubt;
     allerdings dürfen Elemente mit und ohne Schlüssel nicht kombiniert werden.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$data </span><span style="color: #007700">= [<br />    [</span><span style="color: #DD0000">"id" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">"name" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'Tom'</span><span style="color: #007700">],<br />    [</span><span style="color: #DD0000">"id" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #DD0000">"name" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'Fred'</span><span style="color: #007700">],<br />];<br />foreach (</span><span style="color: #0000BB">$data </span><span style="color: #007700">as [</span><span style="color: #DD0000">"id" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$id</span><span style="color: #007700">, </span><span style="color: #DD0000">"name" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$name</span><span style="color: #007700">]) {<br />    echo </span><span style="color: #DD0000">"id: </span><span style="color: #0000BB">$id</span><span style="color: #DD0000">, name: </span><span style="color: #0000BB">$name</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />list(</span><span style="color: #0000BB">1 </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$zweites</span><span style="color: #007700">, </span><span style="color: #0000BB">3 </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$viertes</span><span style="color: #007700">) = [</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">];<br />echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$zweites</span><span style="color: #DD0000">, </span><span style="color: #0000BB">$viertes</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;</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="annotation-interactive examplescode"><pre class="examplescode">id: 1, name: Tom
id: 2, name: Fred

2, 4</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.list-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.each.php" class="function" rel="rdfs-seeAlso">each()</a> - Liefert das aktuelle Schl&uuml;ssel-Wert-Paar eines Arrays und r&uuml;ckt den
   Arrayzeiger vor</span></li>
    <li><span class="function"><a href="function.array.php" class="function" rel="rdfs-seeAlso">array()</a> - Erstellt ein Array</span></li>
    <li><span class="function"><a href="function.extract.php" class="function" rel="rdfs-seeAlso">extract()</a> - Importiert Variablen eines Arrays in die aktuelle Symboltabelle</span></li>
   </ul>
  </p>
 </div>


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