-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy patheach.xml
More file actions
166 lines (164 loc) · 4.46 KB
/
each.xml
File metadata and controls
166 lines (164 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?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
-->