ID:               45135
 Comment by:       felix dot devliegher at gmail dot com
 Reported By:      byraul at gmail dot com
 Status:           Open
 Bug Type:         Unknown/Other Function
 Operating System: linux
 PHP Version:      5.2.6
 New Comment:

This is not a bug, but expected behaviour. The last iteration of the 
foreach with reference value references itself, with a current value of

'one3' at that point, thus saving one3 as last value.


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

[2008-05-30 08:51:12] byraul at gmail dot com

Description:
------------
Reference problems

Reproduce code:
---------------
<?php
$matches = array(
    array('one0', 'two0', 'three0'),
    array('one1', 'two1', 'three1'),
    array('one2', 'two2', 'three2'),
    array('one3', 'two3', 'three3'),
    array('one4', 'two4', 'three4'),
);
foreach($matches as $key=>&$value)
{
}

foreach($matches as $value)
{
    echo $value[0] . PHP_EOL;
}

Expected result:
----------------
one0
one1
one2
one3
one4

Actual result:
--------------
one0
one1
one2
one3
one3


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


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

Reply via email to