foreach &

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@165499 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2004-08-06 08:55:17 +00:00
parent 3aa550f0bf
commit 34091ee69e

View file

@ -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>
@ -542,6 +542,27 @@ foreach (array_expression as $key => $value)
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 &amp;. 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>
<para>