mirror of
https://github.com/php/doc-de.git
synced 2026-03-30 03:02:13 +02:00
git-svn-id: https://svn.php.net/repository/phpdoc/de/trunk@198701 c90b9560-bf6c-de11-be94-00142212c4b1
161 lines
4.2 KiB
XML
161 lines
4.2 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.11 $ -->
|
|
<!-- EN-Revision: 1.17 Maintainer: simp Status: ready -->
|
|
<!-- CREDITS: tom -->
|
|
<refentry id="function.each">
|
|
<refnamediv>
|
|
<refname>each</refname>
|
|
<refpurpose>
|
|
Liefert das aktuelle Paar (Schlüssel und Wert) eines Arrays und
|
|
rückt den Array Cursor vor.
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Beschreibung</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>each</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Liefert das aktuelle Schlüssel- Wertepaar des Arrays
|
|
<parameter>array</parameter>, und erhöht den Array Cursor. Dieses
|
|
Paar wird als Array mit 4 Elementen zurückgegeben, und zwar mit
|
|
den Schlüsseln <literal>0</literal>, <literal>1</literal>,
|
|
<literal>key</literal>, und <literal>value</literal>. Die
|
|
Elemente <literal>0</literal> und <literal>key</literal>
|
|
enthalten den Namen des Schlüssels, <literal>1</literal> und
|
|
<literal>value</literal> den Wert.
|
|
</para>
|
|
<para>
|
|
Zeigt der interne Zeiger hinter das Ende der Array-Inhalte, gibt
|
|
<function>each</function> &false; zurück.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>each</function> Beispiele</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$foo = array("bob", "fred", "jussi", "jouni", "egon", "marliese");
|
|
$bar = each($foo);
|
|
print_r($bar);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<varname>$bar</varname> enthält nun die folgenden Schlüssel/Wert
|
|
Paare:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => bob
|
|
[value] => bob
|
|
[0] => 0
|
|
[key] => 0
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$foo = array("Robert" => "Bob", "Seppo" => "Sepi");
|
|
$bar = each($foo);
|
|
print_r($bar);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<varname>$bar</varname> enthält nun die folgenden Schlüssel/Wert
|
|
Paare:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => Bob
|
|
[value] => Bob
|
|
[0] => Robert
|
|
[key] => Robert
|
|
)
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
<function>each</function> wird typischerweise in Verbindung mit
|
|
<function>list</function> verwendet, um ein Array durchzugehen:
|
|
<example>
|
|
<title>Durchgehen eines Arrays mit <function>each</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$fruit = array('a' => 'Apfel', 'b' => 'Banane', 'c' => 'Preiselbeere');
|
|
|
|
reset($fruit);
|
|
while (list($key, $val) = each($fruit)) {
|
|
echo "$key => $val\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
a => Apfel
|
|
b => Banane
|
|
c => Preiselbeere
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Nachdem <function>each</function> ausgeführt wurde, bleibt der
|
|
Array Cursor beim nächsten Element des Arrays, oder wenn am Ende
|
|
des Arrays angelangt, nach dem letzten Element. Sie müssen
|
|
<function>reset</function> verwenden, wenn Sie das Array erneut
|
|
mittels each durchgehen wollen.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
Da die Zuweisung eines Arrays zu einer anderen Variable den originalen
|
|
Arrayzeiger zurücksetzt, würde unser obiges Beispiel in eine Endlosschleife
|
|
geraten, hätten wir <varname>$fruit</varname> innerhalb der Schleife
|
|
einer anderen Variable zugeordnet.
|
|
</para>
|
|
</caution>
|
|
<para>
|
|
Siehe auch <function>key</function>, <function>list</function>,
|
|
<function>current</function>, <function>reset</function>,
|
|
<function>next</function>, <function>prev</function> und
|
|
<link linkend="control-structures.foreach">foreach</link>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|