svn: /phpdoc/en/trunk/language/control-structures/ foreach.xml

From: Date: Fri, 11 Nov 2011 13:25:03 +0000
Subject: svn: /phpdoc/en/trunk/language/control-structures/ foreach.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9024@lists.php.net to get a copy of this message
gooh Fri, 11 Nov 2011 13:25:03 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=319052 Log: fixes 60255 - Inaccurate statement about foreach copying arrays Changed paths: U phpdoc/en/trunk/language/control-structures/foreach.xml Modified: phpdoc/en/trunk/language/control-structures/foreach.xml =================================================================== --- phpdoc/en/trunk/language/control-structures/foreach.xml 2011-11-11 13:18:14 UTC (rev 319051) +++ phpdoc/en/trunk/language/control-structures/foreach.xml 2011-11-11 13:25:03 UTC (rev 319052) @@ -51,19 +51,13 @@ <para> <note> <para> - Unless the array is <link linkend="language.references">referenced</link>, - <literal>foreach</literal> operates on a copy of - the specified array and not the array itself. <literal>foreach</literal> + <literal>foreach</literal> operates on a copy of the array values unless + <literal>$value</literal> is <link linkend="language.references">referenced</link> + by preceding it with &amp;. <literal>foreach</literal> has some side effects on the array pointer. Don't rely on the array - pointer during or after the foreach without resetting it. + pointer during or after the <literal>foreach</literal> without resetting it. </para> </note> - </para> - <para> - As of PHP 5, you can easily modify array's elements by preceding - <literal>$value</literal> with &amp;. This will assign - <link linkend="language.references">reference</link> instead of copying - the value. <informalexample> <programlisting role="php"> <![CDATA[ @@ -78,8 +72,10 @@ ]]> </programlisting> </informalexample> - This is possible only if iterated array can be referenced (i.e. is - variable), that means the following code won't work: + </para> + <para> + Referencing <literal>$value</literal> is only possible if the iterated array can be + referenced (i.e. if it is a variable). The following code won't work: <informalexample> <programlisting role="php"> <![CDATA[ @@ -87,7 +83,6 @@ foreach (array(1, 2, 3, 4) as &$value) { $value = $value * 2; } - ?> ]]> </programlisting> @@ -128,6 +123,8 @@ ]]> </programlisting> </informalexample> + </para> + <para> The following are also functionally identical: <informalexample> <programlisting role="php">

« previous php.doc.cvs (#9024) next »