danbeck Mon Apr 9 14:50:14 2001 EDT
Modified files:
/phpdoc/en/language control-structures.xml
Log:
notes and examples added to foreach
Index: phpdoc/en/language/control-structures.xml
diff -u phpdoc/en/language/control-structures.xml:1.27
phpdoc/en/language/control-structures.xml:1.28
--- phpdoc/en/language/control-structures.xml:1.27 Mon Apr 9 12:15:45 2001
+++ phpdoc/en/language/control-structures.xml Mon Apr 9 14:50:14 2001
@@ -461,23 +461,31 @@
<para>
<note>
<para>
- When <literal>foreach</literal> first starts executing, the
+ When <literal>foreach</literal> first starts executing, the
internal array pointer is automatically reset to the first element
of the array. This means that you do not need to call
<function>reset</function> before a <literal>foreach</literal>
loop.
- </para>
- </note>
+ </para>
+ </note>
</para>
<para>
<note>
- <para>
- Also note that <literal>foreach</literal> operates on a copy of
- the specified array, not the array itself, therefore the array
- pointer is not modified like with the each construct.
- </para>
+ <para>
+ Also note that <literal>foreach</literal> operates on a copy of
+ the specified array, not the array itself, therefore the array
+ pointer is not modified as with the <function>each</function>
+ construct and changes to the array element returned are not
+ reflected in the original array.
+ </para>
</note>
</para>
+ <note>
+ <para>
+ <literal>foreach</literal> does not support the ability to
+ suppress error messages using '@'.
+ </para>
+ </note>
<para>
You may have noticed that the following are functionally
identical:
@@ -540,6 +548,25 @@
foreach($a as $k => $v) {
print "\$a[$k] => $v.\n";
+}
+
+/* foreach example 4: multi-dimensional arrays */
+
+$a[0][0] = "a";
+$a[0][1] = "b";
+$a[1][0] = "y";
+$a[1][1] = "z";
+
+foreach($a as $v1) {
+ foreach ($v1 as $v2) {
+ print "$v2\n";
+ }
+}
+
+/* foreach example 5: dynamic arrays
+
+foreach(array(1, 2, 3, 4, 5) as $v) {
+ print "$v\n";
}
</programlisting>
</informalexample>