#47702 [Fbk->Opn]: foreach (array(..) as &$value)

From: Date: Wed, 18 Mar 2009 20:30:04 +0000
Subject: #47702 [Fbk->Opn]: foreach (array(..) as &$value)
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2002@lists.php.net to get a copy of this message
 ID:              47702
 User updated by: jidanni at jidanni dot org
 Reported By:     jidanni at jidanni dot org
-Status:          Feedback
+Status:          Open
 Bug Type:        Documentation problem
 PHP Version:     Irrelevant
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2009-03-18 07:24:23] 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 06:14:38] 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;
}

!



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47702&edit=1



Thread (4 messages)

« previous php.doc.bugs (#2002) next »