php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47702 foreach (array(..) as &$value)
Submitted: 2009-03-18 06:14 UTC Modified: 2009-04-21 03:18 UTC
From: jidanni at jidanni dot org Assigned: fa (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jidanni at jidanni dot org
New email:
PHP Version: OS:

 

 [2009-03-18 06:14 UTC] jidanni at jidanni dot org
Description:
------------
In php-doc/html/control-structures.foreach.html
be sure to please mention that you can do

$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}

and

foreach (array(1, 2, 3, 4) as $value) {
    $value = $value * 2;
}

but not

foreach (array(1, 2, 3, 4) as &$value) {
    $value = $value * 2;
}

!


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-18 07:24 UTC] philip@php.net
It already contains this:

"This is possible only if iterated array can be referenced (i.e. is 
variable)."

Do you feel this is unclear? Maybe cleaning up the grammar here is the 
answer?
 [2009-03-18 20:30 UTC] jidanni at jidanni dot org
Yes, an example is worth a thousand words.

And even use something like
foreach(array($bla['a']['b']['c']) as $x){if(4==$x){$x=...}else...
where we even just have one member, and use foreach to make our
program more readable, but ... just ... can't.
 [2009-04-21 03:18 UTC] fa@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of fa
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=996da98b6a63d5b5933b815c866da394bf6f5f0b
Log: fixed bug #47702
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 03:00:02 2026 UTC