I don't know if I'm doing something wrong or if this is a bug.
Very simply: I created an array with values 1-5. I use a foreach loop to
iterate over it to add 1 to the values. It correctly iterates over the
array except for the last value.
Code:
<?php
$test = array(1, 2, 3, 4, 5);
print "original: <br>";
foreach ($test as $part) {
print "($part) ";
}
print "<br> changing: <br>";
foreach ($test as &$part) {
print "($part -> ";
$part ++;
print "$part) ";
}
print "<br>final:<br>";
foreach ($test as $part) {
print "($part) ";
}
print "<br>var dump:<br>";
var_dump($test);
?>
Expected Output:
original:
(1) (2) (3) (4) (5)
changing:
(1 -> 2) (2 -> 3) (3 -> 4) (4 -> 5) (5 -> 6)
final:
(2) (3) (4) (5) (6)
var dump:
array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=>
int(5) }
Actual Output:
original:
(1) (2) (3) (4) (5)
changing:
(1 -> 2) (2 -> 3) (3 -> 4) (4 -> 5) (5 -> 6)
final:
(2) (3) (4) (5) (5)
var dump:
array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> ?(5) }
Any help?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php