mirror of
https://github.com/php/doc-it.git
synced 2026-03-24 15:42:46 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@314534 c90b9560-bf6c-de11-be94-00142212c4b1
167 lines
4.5 KiB
XML
167 lines
4.5 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- splitted from ./it/functions/array.xml, last change in rev 1.1 -->
|
|
<!-- last change to 'each' in en/ tree in rev 1.2 -->
|
|
<!-- EN-Revision: n/a Maintainer: cucinato Status: ready -->
|
|
<!-- OLD-Revision: 1.173/EN.1.2 -->
|
|
<refentry xml:id="function.each" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>each</refname>
|
|
<refpurpose>
|
|
Restituisce la corrente coppia chiave/valore di un array e incrementa
|
|
il puntatore dell'array
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrizione</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>each</methodname>
|
|
<methodparam><type>array</type><parameter>array</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Restituisce la corrente coppia chiave/valore corrente di
|
|
<parameter>array</parameter> e incrementa il puntatore interno dell'array. Questa
|
|
coppia è restituita in un array di quattro elementi, con le chiavi
|
|
<emphasis>0</emphasis>, <emphasis>1</emphasis>,
|
|
<emphasis>key</emphasis>, and
|
|
<emphasis>value</emphasis>. Gli elementi <emphasis>0</emphasis> e
|
|
<emphasis>key</emphasis> contengono il nome della chiave dell'elemento
|
|
dell'array, mentre <emphasis>1</emphasis> e
|
|
<emphasis>value</emphasis> contengono i dati.
|
|
</para>
|
|
<para>
|
|
Se il puntatore interno dell'array punta oltre la fine dei
|
|
contenuti dell'array, <function>each</function> restituisce
|
|
&false;.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>esempi di<function>each</function></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> ora contiene la seguente coppia
|
|
chiave/valore:
|
|
</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> ora contiene la seguente coppia
|
|
chiave/valore:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => Bob
|
|
[value] => Bob
|
|
[0] => Robert
|
|
[key] => Robert
|
|
)
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
<function>each</function> viene normalmente usata in congiunzione con
|
|
<function>list</function> nell'attraversamento di un array; ecco un
|
|
esempio:
|
|
<example>
|
|
<title>Attraversamento di un array con <function>each</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$frutta = array('a' => 'albicocca', 'b' => 'banana', 'c' => 'ciliegia');
|
|
|
|
reset($frutta);
|
|
while (list($chiave, $valore) = each($frutta)) {
|
|
echo "$chiave => $valore\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Outputs:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
a => albicocca
|
|
b => banana
|
|
c => ciliegia
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Dopo l'esecuzione di <function>each</function>, il puntatore dell'array
|
|
viene lasciato sull'elemento successivo, o sull'ultimo
|
|
elemento se si è alla fine dell'array. Si deve utilizzare
|
|
<function>reset</function> se si vuole riattraversare l'array
|
|
usando <function>each</function>.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
Poiché assegnare un array ad un'altra variabile reimposta il
|
|
puntatore, il nostro esempio diventerebbe un loop infinito se
|
|
assegnassimo <varname>$frutta</varname> ad un'altra variabile all'interno
|
|
del ciclo.
|
|
</para>
|
|
</caution>
|
|
<para>
|
|
Vedere anche <function>key</function>, <function>list</function>,
|
|
<function>current</function>, <function>reset</function>,
|
|
<function>next</function>, <function>prev</function> e
|
|
<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:"~/.phpdoc/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
|
|
-->
|