mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
foreach &
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@165499 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
3aa550f0bf
commit
34091ee69e
1 changed files with 22 additions and 1 deletions
|
@ -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 &. 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>
|
||||
|
|
Loading…
Reference in a new issue