vrana Fri Aug 6 04:55:17 2004 EDT
Modified files: /phpdoc/en/language control-structures.xml Log: foreach & http://cvs.php.net/diff.php/phpdoc/en/language/control-structures.xml?r1=1.102&r2=1.103&ty=u Index: phpdoc/en/language/control-structures.xml diff -u phpdoc/en/language/control-structures.xml:1.102 phpdoc/en/language/control-structures.xml:1.103 --- phpdoc/en/language/control-structures.xml:1.102 Fri Aug 6 04:32:48 2004 +++ phpdoc/en/language/control-structures.xml Fri Aug 6 04:55:17 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.102 $ --> +<!-- $Revision: 1.103 $ --> <chapter id="language.control-structures"> <title>Control Structures</title> @@ -541,6 +541,27 @@ <emphasis>is</emphasis> advanced with the processing of the array. Assuming the foreach loop runs to completion, the array's internal pointer will be at the end of the array. + </para> + <para> + As of PHP 5, you can easily modify array's elements by preceding + <literal>$value</literal> with &. This will assign + <link linkend="language.references">reference</link> instead of copying + the value. + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +$arr = array(1, 2, 3, 4); +foreach ($arr as &$value) { + $value = $value * 2; +} +// $arr is now array(2, 4, 6, 8) +?> +]]> + </programlisting> + </informalexample> + This is possible only if iterated array can be referenced (i.e. is + variable). </para> </note> </para>